From 548405335d238de73f9ff9619be3ff695501ed7c Mon Sep 17 00:00:00 2001 From: haozhong Date: Mon, 13 Dec 2021 21:41:24 +0800 Subject: [PATCH] change the default package.json to the current dir --- index.js | 2 +- test/specs.js | 2 ++ test/src/node_modules/module-alias/package.json | 10 ++++++++++ 3 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 test/src/node_modules/module-alias/package.json diff --git a/index.js b/index.js index 8f2e570..2acfdba 100644 --- a/index.js +++ b/index.js @@ -163,7 +163,7 @@ function init (options) { // above the node_modules directory, // Or that package.json is in the node process' current working directory (when // running a package manager script, e.g. `yarn start` / `npm run start`) - candidatePackagePaths = [nodePath.join(__dirname, '../..'), process.cwd()] + candidatePackagePaths = [process.cwd(), nodePath.join(__dirname, '../..')] } var npmPackage diff --git a/test/specs.js b/test/specs.js index 4793827..d1b2783 100644 --- a/test/specs.js +++ b/test/specs.js @@ -151,6 +151,8 @@ describe('module-alias', function () { }) it('should import default settings from ../../package.json', function () { + process.chdir(moduleAliasDir) + linkedModuleAlias() expectAliasesToBeImported() diff --git a/test/src/node_modules/module-alias/package.json b/test/src/node_modules/module-alias/package.json new file mode 100644 index 0000000..a072a27 --- /dev/null +++ b/test/src/node_modules/module-alias/package.json @@ -0,0 +1,10 @@ +{ + "name": "test-app", + "_moduleDirectories": ["../../node_modules_custom"], + "_moduleAliases": { + "@src": "../..", + "@foo": "../../foo/index.js", + "@bar": "../../bar", + "some/foo": "../../foo" + } +}