Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CON-903 Make library npm-compatible #88

Merged
merged 3 commits into from
Sep 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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",
chivchila marked this conversation as resolved.
Show resolved Hide resolved
"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