Closed fusionstrings closed 6 years ago
I'm not quite following, can you explain the exact workflow here?
If npm package ships with esm version under 'module' field of package.json then while using jspm cli, I could use jspm --override ...
and it works out perfectly but instead If I am using 'rollup-plugin-jspm', it will resolve to 'main' field of package.json. How to use the override of package.json while using this plugin.
rollup-plugin-jspm will use the versions of packages in the jspm_packages folder.
Note that jspm itself supports node_modules as a fallback for anything not found in jspm_packages. This can be tested with jspm resolve package-name
which will show where it is locating the package from (and can be run from anywhere, it doesn't need to be a jspm project).
So if using rollup-plugin-jspm in a jspm project, the overrides will apply fine. If using it in a non-jspm project (node_modules), then you'd need to hook into Rollup's resolve hook yourself to use the module main.
Does that answer your question?
It doesn't seem to be working this way. I am getting following error. Setup is same as in https://github.com/jspm/jspm2-cli/issues/32
> rollup -c
./core/index.js → dist/build.js...
[!] Error: 'import' and 'export' may only appear at the top level
jspm_packages/npm/preact@8.2.7/dist/preact.esm.js?dew (1029:2)
Error: 'import' and 'export' may only appear at the top level
at error (/Users/dilip/git/lab/lazy-redux/node_modules/rollup/dist/rollup.js:168:15)
at Module.error (/Users/dilip/git/lab/lazy-redux/node_modules/rollup/dist/rollup.js:17602:9)
at tryParse (/Users/dilip/git/lab/lazy-redux/node_modules/rollup/dist/rollup.js:17303:16)
at Module.setSource (/Users/dilip/git/lab/lazy-redux/node_modules/rollup/dist/rollup.js:17359:24)
at /Users/dilip/git/lab/lazy-redux/node_modules/rollup/dist/rollup.js:19939:20
at <anonymous>
It seems plugin is resolving to correct file but dew transform is applied on preact.esm.js.
Can you confirm the contents of jspm_packages/npm/preact@8.2.7/package.json?
{
"name": "preact",
"version": "8.2.7",
"description": "Fast 3kb React alternative with the same ES6 API. Components & Virtual DOM.",
"main": "dist/preact.js",
"jsnext:main": "dist/preact.esm.js",
"module": "dist/preact.esm.js",
"dev:main": "dist/preact.dev.js",
"minified:main": "dist/preact.min.js",
"scripts": {
"clean": "rimraf dist/ devtools.js devtools.js.map debug.js debug.js.map",
"copy-flow-definition": "copyfiles -f src/preact.js.flow dist",
"copy-typescript-definition": "copyfiles -f src/preact.d.ts dist",
"build": "npm-run-all --silent clean transpile copy-flow-definition copy-typescript-definition strip optimize minify size",
"flow": "flow",
"transpile:main": "rollup -c config/rollup.config.js",
"transpile:devtools": "rollup -c config/rollup.config.devtools.js",
"transpile:esm": "rollup -c config/rollup.config.esm.js",
"transpile:debug": "babel debug/ -o debug.js -s",
"transpile": "npm-run-all transpile:main transpile:esm transpile:devtools transpile:debug",
"optimize": "uglifyjs dist/preact.dev.js -c conditionals=false,sequences=false,loops=false,join_vars=false,collapse_vars=false --pure-funcs=Object.defineProperty --mangle-props --mangle-regex=\"/^(_|normalizedNodeName|nextBase|prev[CPS]|_parentC)/\" --name-cache config/properties.json -b width=120,quote_style=3 -o dist/preact.js -p relative --in-source-map dist/preact.dev.js.map --source-map dist/preact.js.map",
"minify": "uglifyjs dist/preact.js -c collapse_vars,evaluate,screw_ie8,unsafe,loops=false,keep_fargs=false,pure_getters,unused,dead_code -m -o dist/preact.min.js -p relative --in-source-map dist/preact.js.map --source-map dist/preact.min.js.map",
"strip:main": "jscodeshift --run-in-band -s -t config/codemod-strip-tdz.js dist/preact.dev.js && jscodeshift --run-in-band -s -t config/codemod-const.js dist/preact.dev.js && jscodeshift --run-in-band -s -t config/codemod-let-name.js dist/preact.dev.js",
"strip:esm": "jscodeshift --run-in-band -s -t config/codemod-strip-tdz.js dist/preact.esm.js && jscodeshift --run-in-band -s -t config/codemod-const.js dist/preact.esm.js && jscodeshift --run-in-band -s -t config/codemod-let-name.js dist/preact.esm.js",
"strip": "npm-run-all strip:main strip:esm",
"size": "node -e \"process.stdout.write('gzip size: ')\" && gzip-size --raw dist/preact.min.js",
"test": "npm-run-all lint --parallel test:mocha test:karma test:ts test:flow test:size",
"test:flow": "flow check",
"test:ts": "tsc -p test/ts/",
"test:mocha": "mocha --recursive --require babel-register test/shared test/node",
"test:karma": "karma start test/karma.conf.js --single-run",
"test:mocha:watch": "npm run test:mocha -- --watch",
"test:karma:watch": "npm run test:karma -- no-single-run",
"test:size": "bundlesize",
"lint": "eslint debug devtools src test",
"prepublish": "npm run build",
"smart-release": "npm run build && npm test && git commit -am $npm_package_version && git tag $npm_package_version && git push && git push --tags && npm publish",
"release": "cross-env npm run smart-release",
"postinstall": "node -e \"console.log('\\u001b[35m\\u001b[1mLove Preact? You can now donate to our open collective:\\u001b[22m\\u001b[39m\\n > \\u001b[34mhttps://opencollective.com/preact/donate\\u001b[0m')\""
},
"eslintConfig": {
"extends": "./config/eslint-config.js"
},
"typings": "./dist/preact.d.ts",
"repository": {
"type": "git",
"url": "https://github.com/developit/preact.git"
},
"files": [
"devtools",
"debug",
"src",
"dist",
"devtools.js",
"devtools.js.map",
"debug.js",
"debug.js.map",
"typings.json"
],
"keywords": [
"preact",
"react",
"virtual dom",
"vdom",
"components",
"virtual",
"dom"
],
"author": "Jason Miller <jason@developit.ca>",
"license": "MIT",
"bugs": {
"url": "https://github.com/developit/preact/issues"
},
"homepage": "https://github.com/developit/preact",
"devDependencies": {
"babel-cli": "^6.24.1",
"babel-core": "^6.24.1",
"babel-eslint": "^7.2.3",
"babel-loader": "^7.0.0",
"babel-plugin-transform-object-rest-spread": "^6.23.0",
"babel-plugin-transform-react-jsx": "^6.24.1",
"babel-preset-env": "^1.5.1",
"bundlesize": "^0.13.2",
"chai": "^3.4.1",
"copyfiles": "^1.0.0",
"core-js": "^2.4.1",
"coveralls": "^2.11.15",
"cross-env": "^3.1.3",
"diff": "^3.0.0",
"eslint": "^3.0.0",
"eslint-plugin-react": "^6.0.0",
"flow-bin": "^0.54.1",
"gzip-size-cli": "^2.0.0",
"isparta-loader": "^2.0.0",
"jscodeshift": "^0.3.25",
"karma": "^1.1.0",
"karma-babel-preprocessor": "^5.2.2",
"karma-chai": "^0.1.0",
"karma-chai-sinon": "^0.1.5",
"karma-chrome-launcher": "^2.0.0",
"karma-coverage": "^1.0.0",
"karma-mocha": "^1.1.1",
"karma-mocha-reporter": "^2.0.4",
"karma-phantomjs-launcher": "^1.0.1",
"karma-sauce-launcher": "^1.1.0",
"karma-source-map-support": "^1.2.0",
"karma-sourcemap-loader": "^0.3.6",
"karma-webpack": "^2.0.3",
"mocha": "^3.0.1",
"npm-run-all": "^4.0.0",
"phantomjs-prebuilt": "^2.1.7",
"rimraf": "^2.5.3",
"rollup": "^0.48.2",
"rollup-plugin-babel": "^3.0.2",
"rollup-plugin-memory": "^2.0.0",
"rollup-plugin-node-resolve": "^3.0.0",
"sinon": "^2.2.0",
"sinon-chai": "^2.8.0",
"typescript": "^2.2.2",
"uglify-js": "^2.7.5",
"webpack": "^2.4.1"
},
"greenkeeper": {
"ignore": [
"babel-cli",
"babel-core",
"babel-eslint",
"babel-loader",
"jscodeshift",
"rollup-plugin-babel"
]
},
"bundlesize": [
{
"path": "./dist/preact.min.js",
"threshold": "4Kb"
}
],
"mains": {
"default": "dist/preact.esm.js"
}
}
Note how there is no "mode": "esm"
there. Perhaps ensure this is in the override?
(perhaps you are seeing how jspm 2.0 is much more predictable by being based on a resolver spec already...)
(although yes, error messages in these cases can be improved! And providing correciton behaviours!)
ohh, it was altogether my mistake. Works now. I apologise for time misunderstanding
dependencies can be overridden using
jspm install --override
but since rollup usesnpm install
how to override dependencies?context
Related https://github.com/jspm/jspm2-cli/issues/32