Skip to content

Commit

Permalink
Merge pull request #88 from Financial-Times/make_npm_compatible
Browse files Browse the repository at this point in the history
CON-903 Make library npm-compatible
  • Loading branch information
chivchila authored Sep 3, 2021
2 parents 5e1a03c + 41f4938 commit 73d6b5d
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 4 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ Verify that the Sass can compile by running
$ npx sass ./test/main.scss --load-path=./bower_components/
```

And by running:

```sh
$ npx sass ./test/main.scss --load-path=./node_modules --load-path=./node_modules/@financial-times
```

### Developing with a next app

Instruction for developing the library within a next app will be are in development ([ACC-1156](https://financialtimes.atlassian.net/browse/ACC-1156)).
Expand Down
1 change: 0 additions & 1 deletion bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
"o-buttons": "^6.0.2",
"o-overlay": "^3.0.0",
"o-tracking": "^2.0.3",
"superstore": "^2.1.0",
"o-visual-effects": "^3.0.0",
"o-message": "^4.1.8"
}
Expand Down
1 change: 1 addition & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ module.exports = {
transform: {
'.(js|jsx)': '@sucrase/jest-plugin'
},
transformIgnorePatterns: ['/node_modules//(?!(@financial-times)/)'],
};
15 changes: 12 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,16 @@
"webpack-sources": "^1.0.1",
"webpack-stats-plugin": "^0.1.1"
},
"dependencies": {},
"dependencies": {
"n-ui-foundations": "github:financial-times/n-ui-foundations#nobower",
"next-session-client": "^3.0.1",
"o-buttons": "npm:@financial-times/o-buttons@^6.0.2",
"o-overlay": "npm:@financial-times/o-overlay@^3.0.0",
"o-tracking": "npm:@financial-times/o-tracking@^2.0.3",
"o-visual-effects": "npm:@financial-times/o-visual-effects@^3.0.0",
"o-message": "npm:@financial-times/o-message@^4.1.8",
"superstore": "^2.1.0"
},
"config": {},
"engines": {
"node": "12.x"
Expand All @@ -45,8 +54,8 @@
"husky": {
"hooks": {
"commit-msg": "node_modules/.bin/secret-squirrel-commitmsg",
"pre-commit": "node_modules/.bin/secret-squirrel",
"pre-commit": "node_modules/.bin/secret-squirrel && node ./scripts/fromBowerToNpm.js",
"pre-push": "make verify -j3"
}
}
}
}
31 changes: 31 additions & 0 deletions scripts/fromBowerToNpm.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
const fs = require('fs');
const bowerPackage = require('../bower.json');
const npmPackage = require('../package.json');

function standardNpmPackage (version, name) {
return `npm:@financial-times/${name}@${version}`;
}

const resolutionMap = {
'n-ui-foundations': () => 'github:financial-times/n-ui-foundations#nobower',
'next-session-client': (version) => `${version}`,
'o-buttons': standardNpmPackage,
'o-overlay': standardNpmPackage,
'o-tracking': standardNpmPackage,
'o-visual-effects': standardNpmPackage,
'o-message': standardNpmPackage,
};

for (const dependency in bowerPackage.dependencies) {
if (!resolutionMap[dependency]) {
throw new Error(`Please update fromBowerToNpm resolution map with the Bower package ${dependency}, so it will be usable also from NPM consumers`
);
} else {
npmPackage.dependencies[dependency] = resolutionMap[dependency](
bowerPackage.dependencies[dependency],
dependency
);
}
}

fs.writeFileSync('package.json', JSON.stringify(npmPackage, null, 2));
1 change: 1 addition & 0 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ const extractOptions = [{
sourcemap: true,
includePaths: [
path.resolve('./bower_components'),
path.resolve('./node_modules'),
path.resolve('./node_modules/@financial-times')
],
// NOTE: This line is important for preservation of comments needed by the css-extract-block plugin
Expand Down

0 comments on commit 73d6b5d

Please sign in to comment.