Skip to content

Commit

Permalink
vx: vx_allow_resolve
Browse files Browse the repository at this point in the history
  • Loading branch information
ealush committed Jun 4, 2023
1 parent b427da2 commit 31fe471
Show file tree
Hide file tree
Showing 12 changed files with 37 additions and 8 deletions.
3 changes: 2 additions & 1 deletion packages/anyone/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -167,5 +167,6 @@
"url": "https://github.com/ealush/vest.git/issues"
},
"unpkg": "./dist/umd/anyone.production.js",
"jsdelivr": "./dist/umd/anyone.production.js"
"jsdelivr": "./dist/umd/anyone.production.js",
"vxAllowResolve": []
}
3 changes: 2 additions & 1 deletion packages/context/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,6 @@
"url": "https://github.com/ealush/vest.git/issues"
},
"unpkg": "./dist/umd/context.production.js",
"jsdelivr": "./dist/umd/context.production.js"
"jsdelivr": "./dist/umd/context.production.js",
"vxAllowResolve": []
}
3 changes: 2 additions & 1 deletion packages/n4s/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -144,5 +144,6 @@
"url": "https://github.com/ealush/vest.git/issues"
},
"unpkg": "./dist/umd/n4s.production.js",
"jsdelivr": "./dist/umd/n4s.production.js"
"jsdelivr": "./dist/umd/n4s.production.js",
"vxAllowResolve": []
}
3 changes: 2 additions & 1 deletion packages/vast/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,6 @@
"./*": "./*"
},
"unpkg": "./dist/umd/vast.production.js",
"jsdelivr": "./dist/umd/vast.production.js"
"jsdelivr": "./dist/umd/vast.production.js",
"vxAllowResolve": []
}
3 changes: 2 additions & 1 deletion packages/vest-utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,6 @@
},
"./package.json": "./package.json",
"./*": "./*"
}
},
"vxAllowResolve": []
}
3 changes: 2 additions & 1 deletion packages/vest/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -227,5 +227,6 @@
},
"./package.json": "./package.json",
"./*": "./*"
}
},
"vxAllowResolve": []
}
3 changes: 2 additions & 1 deletion packages/vestjs-runtime/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,6 @@
},
"./package.json": "./package.json",
"./*": "./*"
}
},
"vxAllowResolve": []
}
6 changes: 6 additions & 0 deletions vx/config/rollup/getPlugins.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// const compiler = require('@ampproject/rollup-plugin-closure-compiler');
const { nodeResolve } = require('@rollup/plugin-node-resolve');
const replace = require('@rollup/plugin-replace');
const _ = require('lodash');
const { terser } = require('rollup-plugin-terser');
Expand All @@ -21,6 +22,11 @@ module.exports = function getPlugins({
namespace = undefined,
} = {}) {
const plugins = [
nodeResolve({
resolveOnly: dep => {
return packageJson.getVxAllowResolve(packageName, dep);
},
}),
replace({
preventAssignment: true,
values: {
Expand Down
9 changes: 8 additions & 1 deletion vx/config/rollup/plugins/handleExports.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,14 @@ function writePackageJson(name, exportPath, { namespace } = {}) {
let pkgJson = generatePackageJson(name, namespace);

if (isMainExport(name)) {
pkgJson = { ...packageJson(name), ...pkgJson };
const orig = packageJson(name);

const preserve = {
[opts.vx_config.VX_ALLOW_RESOLVE]:
orig[opts.vx_config.VX_ALLOW_RESOLVE] ?? [],
};

pkgJson = { ...orig, ...pkgJson, ...preserve };
}

fse.writeJSONSync(
Expand Down
3 changes: 3 additions & 0 deletions vx/opts.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,7 @@ module.exports = {
CJS: 'cjs',
ES: 'es',
},
vx_config: {
VX_ALLOW_RESOLVE: 'vxAllowResolve',
},
};
1 change: 1 addition & 0 deletions vx/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"bin": "./cli.js",
"dependencies": {
"@ampproject/rollup-plugin-closure-compiler": "^0.27.0",
"@rollup/plugin-node-resolve": "^15.1.0",
"@rollup/plugin-replace": "^5.0.2",
"context": "3.0.2",
"date-fns": "^2.30.0",
Expand Down
5 changes: 5 additions & 0 deletions vx/util/packageJson.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,9 @@ function packageJson(pkgName = usePackage()) {
return JSON.parse(jsonString);
}

function getVxAllowResolve(pkgName = usePackage(), dep) {
return (packageJson(pkgName).vxAllowResolve || []).includes(dep);
}

module.exports = packageJson;
module.exports.getVxAllowResolve = getVxAllowResolve;

0 comments on commit 31fe471

Please sign in to comment.