Try to fix cosmiconfig in the built version of Prettier (#2930)

master
Simon Lydell 2017-09-29 09:27:50 +02:00 committed by GitHub
parent 0d756080b5
commit 63916beebb
2 changed files with 23 additions and 2 deletions

View File

@ -11,7 +11,14 @@ export default Object.assign(baseConfig, {
banner: "#!/usr/bin/env node",
plugins: [
replace({
"#!/usr/bin/env node": ""
"#!/usr/bin/env node": "",
// The require-from-string module (a dependency of cosmiconfig) assumes
// that `module.parent` exists, but it only does for `require`:ed modules.
// Usually, require-from-string is _always_ `require`:ed, but when bundled
// with rollup the module is turned into a plain function located directly
// in bin/prettier.js so `module.parent` does not exist. Defaulting to
// `module` instead seems to work.
"module.parent": "(module.parent || module)"
}),
json(),
resolve({ preferBuiltins: true }),

View File

@ -2,11 +2,25 @@ import baseConfig from "./rollup.base.config.js";
import resolve from "rollup-plugin-node-resolve";
import commonjs from "rollup-plugin-commonjs";
import json from "rollup-plugin-json";
import replace from "rollup-plugin-replace";
export default Object.assign(baseConfig, {
entry: "index.js",
dest: "dist/index.js",
format: "cjs",
plugins: [json(), resolve({ preferBuiltins: true }), commonjs()],
plugins: [
replace({
// The require-from-string module (a dependency of cosmiconfig) assumes
// that `module.parent` exists, but it only does for `require`:ed modules.
// Usually, require-from-string is _always_ `require`:ed, but when bundled
// with rollup the module is turned into a plain function located directly
// in index.js so `module.parent` does not exist. Defaulting to `module`
// instead seems to work.
"module.parent": "(module.parent || module)"
}),
json(),
resolve({ preferBuiltins: true }),
commonjs()
],
external: ["assert"]
});