@bobfrankston/npmglobalize 1.0.121 → 1.0.122
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib.js +43 -12
- package/package.json +1 -1
package/lib.js
CHANGED
|
@@ -814,6 +814,18 @@ export function restoreDeps(pkg, verbose = false) {
|
|
|
814
814
|
}
|
|
815
815
|
}
|
|
816
816
|
}
|
|
817
|
+
// Remove bundledDependencies added for workspace hoisting
|
|
818
|
+
if (pkg['.bundledDependencies']) {
|
|
819
|
+
if (pkg['.bundledDependencies'].length === 0) {
|
|
820
|
+
delete pkg.bundledDependencies;
|
|
821
|
+
delete pkg.bundleDependencies;
|
|
822
|
+
}
|
|
823
|
+
else {
|
|
824
|
+
pkg.bundledDependencies = pkg['.bundledDependencies'];
|
|
825
|
+
}
|
|
826
|
+
delete pkg['.bundledDependencies'];
|
|
827
|
+
restored = true;
|
|
828
|
+
}
|
|
817
829
|
return restored;
|
|
818
830
|
}
|
|
819
831
|
/** Check if .dependencies exist (already transformed) */
|
|
@@ -2998,16 +3010,18 @@ export async function globalize(cwd, options = {}, configOptions = {}) {
|
|
|
2998
3010
|
console.log(' No file: dependencies found.');
|
|
2999
3011
|
}
|
|
3000
3012
|
// Hoist workspace sub-package deps into root for publishing/global install.
|
|
3001
|
-
// npm install -g only installs root-level dependencies
|
|
3002
|
-
//
|
|
3003
|
-
//
|
|
3013
|
+
// npm install -g only installs root-level dependencies and doesn't process
|
|
3014
|
+
// the workspaces field, so:
|
|
3015
|
+
// 1. Third-party deps (express, ws, etc.) must be in root dependencies
|
|
3016
|
+
// 2. Sibling workspace packages must be in bundledDependencies so npm
|
|
3017
|
+
// includes them in the tarball's node_modules/
|
|
3018
|
+
// All changes are temporary — restoreDeps removes them via .dependencies backup.
|
|
3004
3019
|
if (pkg.workspaces) {
|
|
3005
3020
|
const wsPatterns = Array.isArray(pkg.workspaces) ? pkg.workspaces : pkg.workspaces.packages || [];
|
|
3006
3021
|
// Collect all workspace sub-package dirs
|
|
3007
3022
|
const wsDirs = [];
|
|
3008
3023
|
for (const pattern of wsPatterns) {
|
|
3009
3024
|
if (pattern.includes('*')) {
|
|
3010
|
-
// Glob pattern like "packages/*" — enumerate subdirectories
|
|
3011
3025
|
const baseDir = path.resolve(cwd, pattern.replace(/\/?\*$/, ''));
|
|
3012
3026
|
if (!fs.existsSync(baseDir))
|
|
3013
3027
|
continue;
|
|
@@ -3017,14 +3031,13 @@ export async function globalize(cwd, options = {}, configOptions = {}) {
|
|
|
3017
3031
|
}
|
|
3018
3032
|
}
|
|
3019
3033
|
else {
|
|
3020
|
-
// Direct directory like "client"
|
|
3021
3034
|
const dir = path.resolve(cwd, pattern);
|
|
3022
3035
|
if (fs.existsSync(dir))
|
|
3023
3036
|
wsDirs.push(dir);
|
|
3024
3037
|
}
|
|
3025
3038
|
}
|
|
3026
|
-
// Collect
|
|
3027
|
-
const
|
|
3039
|
+
// Collect workspace package names and their relative paths
|
|
3040
|
+
const wsPackages = new Map(); // name -> relative dir
|
|
3028
3041
|
for (const dir of wsDirs) {
|
|
3029
3042
|
const pkgJsonPath = path.join(dir, 'package.json');
|
|
3030
3043
|
if (!fs.existsSync(pkgJsonPath))
|
|
@@ -3032,11 +3045,11 @@ export async function globalize(cwd, options = {}, configOptions = {}) {
|
|
|
3032
3045
|
try {
|
|
3033
3046
|
const subPkg = JSON.parse(fs.readFileSync(pkgJsonPath, 'utf-8'));
|
|
3034
3047
|
if (subPkg.name)
|
|
3035
|
-
|
|
3048
|
+
wsPackages.set(subPkg.name, path.relative(cwd, dir).replace(/\\/g, '/'));
|
|
3036
3049
|
}
|
|
3037
3050
|
catch { /* skip */ }
|
|
3038
3051
|
}
|
|
3039
|
-
// Find deps in sub-packages not present in root
|
|
3052
|
+
// Find third-party deps in sub-packages not present in root
|
|
3040
3053
|
const rootDeps = { ...pkg.dependencies, ...pkg.devDependencies };
|
|
3041
3054
|
const hoisted = [];
|
|
3042
3055
|
for (const dir of wsDirs) {
|
|
@@ -3052,8 +3065,8 @@ export async function globalize(cwd, options = {}, configOptions = {}) {
|
|
|
3052
3065
|
}
|
|
3053
3066
|
const deps = subPkg.dependencies || {};
|
|
3054
3067
|
for (const [dep, ver] of Object.entries(deps)) {
|
|
3055
|
-
if (
|
|
3056
|
-
continue; // sibling workspace —
|
|
3068
|
+
if (wsPackages.has(dep))
|
|
3069
|
+
continue; // sibling workspace — handled via bundledDependencies
|
|
3057
3070
|
if (dep in rootDeps)
|
|
3058
3071
|
continue; // already in root
|
|
3059
3072
|
if (hoisted.some(m => m.dep === dep))
|
|
@@ -3061,7 +3074,8 @@ export async function globalize(cwd, options = {}, configOptions = {}) {
|
|
|
3061
3074
|
hoisted.push({ dep, version: ver, from: subPkg.name || path.basename(dir) });
|
|
3062
3075
|
}
|
|
3063
3076
|
}
|
|
3064
|
-
|
|
3077
|
+
const needsUpdate = hoisted.length > 0 || wsPackages.size > 0;
|
|
3078
|
+
if (needsUpdate) {
|
|
3065
3079
|
// Ensure .dependencies backup exists so restoreDeps will remove hoisted deps
|
|
3066
3080
|
if (!pkg['.dependencies']) {
|
|
3067
3081
|
pkg['.dependencies'] = { ...(pkg.dependencies || {}) };
|
|
@@ -3069,6 +3083,7 @@ export async function globalize(cwd, options = {}, configOptions = {}) {
|
|
|
3069
3083
|
}
|
|
3070
3084
|
if (!pkg.dependencies)
|
|
3071
3085
|
pkg.dependencies = {};
|
|
3086
|
+
// Hoist third-party deps
|
|
3072
3087
|
for (const m of hoisted) {
|
|
3073
3088
|
let version = m.version;
|
|
3074
3089
|
if (typeof version === 'string' && version.startsWith('file:')) {
|
|
@@ -3084,6 +3099,22 @@ export async function globalize(cwd, options = {}, configOptions = {}) {
|
|
|
3084
3099
|
pkg.dependencies[m.dep] = version;
|
|
3085
3100
|
console.log(colors.green(` + hoisted ${m.dep}: ${version} (from ${m.from})`));
|
|
3086
3101
|
}
|
|
3102
|
+
// Add workspace sibling packages to dependencies + bundledDependencies
|
|
3103
|
+
// so npm includes them in the tarball's node_modules/
|
|
3104
|
+
// Save original bundledDependencies for restore
|
|
3105
|
+
const origBundled = pkg.bundledDependencies || pkg.bundleDependencies || [];
|
|
3106
|
+
pkg['.bundledDependencies'] = [...origBundled];
|
|
3107
|
+
const bundled = [...origBundled];
|
|
3108
|
+
for (const [name, relDir] of wsPackages) {
|
|
3109
|
+
if (!(name in pkg.dependencies)) {
|
|
3110
|
+
pkg.dependencies[name] = 'file:./' + relDir;
|
|
3111
|
+
}
|
|
3112
|
+
if (!bundled.includes(name)) {
|
|
3113
|
+
bundled.push(name);
|
|
3114
|
+
}
|
|
3115
|
+
console.log(colors.green(` + bundled workspace ${name} (./${relDir})`));
|
|
3116
|
+
}
|
|
3117
|
+
pkg.bundledDependencies = bundled;
|
|
3087
3118
|
if (!dryRun) {
|
|
3088
3119
|
writePackageJson(cwd, pkg);
|
|
3089
3120
|
}
|