webpack-contrib / webpack-defaults

Defaults to be shared across webpack projects
MIT License
108 stars 28 forks source link

fix: fix error occurred when cli copy files and add compatible logic #184

Closed GaoYYYang closed 4 years ago

GaoYYYang commented 4 years ago

This PR contains a:

Motivation / Use-Case

I found some errors when i use webpack-defaults cli. At first,when i run it in an empty directory(without existing package.json), it will fail。

/Users/bytedance/.nvm/versions/node/v12.16.3/lib/node_modules/@webpack-contrib/defaults/dist/tasks/package.js:67
      defaults: existing.scripts.defaults || 'webpack-defaults'
                                 ^

TypeError: Cannot read property 'defaults' of undefined
    at module.exports (/Users/bytedance/.nvm/versions/node/v12.16.3/lib/node_modules/@webpack-contrib/defaults/dist/tasks/package.js:67:34)
    at /Users/bytedance/.nvm/versions/node/v12.16.3/lib/node_modules/@webpack-contrib/defaults/dist/index.js:18:5
    at Array.forEach (<anonymous>)
    at webpackDefaults (/Users/bytedance/.nvm/versions/node/v12.16.3/lib/node_modules/@webpack-contrib/defaults/dist/index.js:15:9)
    at Object.<anonymous> (/Users/bytedance/.nvm/versions/node/v12.16.3/lib/node_modules/@webpack-contrib/defaults/bin/index.js:3:19)
    at Module._compile (internal/modules/cjs/loader.js:1133:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1153:10)
    at Module.load (internal/modules/cjs/loader.js:977:32)
    at Function.Module._load (internal/modules/cjs/loader.js:877:14)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:74:12)

Second,after i overcome the first problem by creating a package.json file, error show up when copy files.

Create test/loader.test.js
(node:79169) UnhandledPromiseRejectionWarning: MrmError: copyFiles: source file not found: /Users/bytedance/.nvm/versions/node/v12.16.3/lib/node_modules/@webpack-contrib/defaults/templates/test/options.test.js
    at /Users/bytedance/.nvm/versions/node/v12.16.3/lib/node_modules/@webpack-contrib/defaults/node_modules/mrm-core/src/fs.js:32:10
    at Array.forEach (<anonymous>)
    at copyFiles (/Users/bytedance/.nvm/versions/node/v12.16.3/lib/node_modules/@webpack-contrib/defaults/node_modules/mrm-core/src/fs.js:29:21)
    at /Users/bytedance/.nvm/versions/node/v12.16.3/lib/node_modules/@webpack-contrib/defaults/dist/tasks/templates.js:26:7
(node:79169) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:79169) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

Then,when i excute npm test, prettier will exit status 1 like that :

> test@1.0.0 lint:prettier /Users/bytedance/Documents/work/code/awebpack/test
> prettier "{**/*,*}.js" --list-different

.eslintrc.js
.prettierrc.js
babel.config.js
commitlint.config.js
husky.config.js
lint-staged.config.js
src/cjs.js
src/index.js
test/helpers/normalizeErrors.js
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! test@1.0.0 lint:prettier: `prettier "{**/*,*}.js" --list-different`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the test@1.0.0 lint:prettier script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/bytedance/.npm/_logs/2020-06-29T13_39_42_161Z-debug.log

At last, i found it would't generator the script defaults in my local package.json

I have fix all problems above.

Breaking Changes

Additional Info

jsf-clabot commented 4 years ago

CLA assistant check
Thank you for your submission, we really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.


gaoyang.lamb seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.

GaoYYYang commented 4 years ago

I have signed the CLA. But status was not updated yet