isolate-package 1.4.0 → 1.4.1-0
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/dist/index.cjs +1000 -0
- package/dist/index.cjs.map +1 -0
- package/dist/{chunk-PXDYN4JI.mjs → index.js} +17 -18
- package/dist/index.js.map +1 -0
- package/dist/isolate-bin.cjs +1003 -0
- package/dist/isolate-bin.cjs.map +1 -0
- package/dist/isolate-bin.js.map +1 -0
- package/dist/isolate-bin.mjs +966 -7
- package/package.json +11 -5
- package/dist/chunk-PXDYN4JI.mjs.map +0 -1
- package/dist/index.mjs +0 -7
- package/dist/index.mjs.map +0 -1
- package/dist/isolate-bin.mjs.map +0 -1
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,1000 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/index.ts
|
|
31
|
+
var src_exports = {};
|
|
32
|
+
__export(src_exports, {
|
|
33
|
+
isolate: () => isolate
|
|
34
|
+
});
|
|
35
|
+
module.exports = __toCommonJS(src_exports);
|
|
36
|
+
|
|
37
|
+
// node_modules/.pnpm/tsup@6.7.0_typescript@5.3.2/node_modules/tsup/assets/cjs_shims.js
|
|
38
|
+
var getImportMetaUrl = () => typeof document === "undefined" ? new URL("file:" + __filename).href : document.currentScript && document.currentScript.src || new URL("main.js", document.baseURI).href;
|
|
39
|
+
var importMetaUrl = /* @__PURE__ */ getImportMetaUrl();
|
|
40
|
+
|
|
41
|
+
// src/isolate.ts
|
|
42
|
+
var import_fs_extra14 = __toESM(require("fs-extra"), 1);
|
|
43
|
+
var import_node_assert6 = __toESM(require("assert"), 1);
|
|
44
|
+
var import_node_path15 = __toESM(require("path"), 1);
|
|
45
|
+
|
|
46
|
+
// src/utils/filter-object-undefined.ts
|
|
47
|
+
function filterObjectUndefined(object) {
|
|
48
|
+
return Object.fromEntries(
|
|
49
|
+
Object.entries(object).filter(([_, value]) => value !== void 0)
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// src/utils/get-dirname.ts
|
|
54
|
+
var import_url = require("url");
|
|
55
|
+
function getDirname(importMetaUrl2) {
|
|
56
|
+
return (0, import_url.fileURLToPath)(new URL(".", importMetaUrl2));
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// src/utils/get-error-message.ts
|
|
60
|
+
function getErrorMessage(error) {
|
|
61
|
+
return toErrorWithMessage(error).message;
|
|
62
|
+
}
|
|
63
|
+
function isErrorWithMessage(error) {
|
|
64
|
+
return typeof error === "object" && error !== null && "message" in error;
|
|
65
|
+
}
|
|
66
|
+
function toErrorWithMessage(maybeError) {
|
|
67
|
+
if (isErrorWithMessage(maybeError))
|
|
68
|
+
return maybeError;
|
|
69
|
+
try {
|
|
70
|
+
return new Error(JSON.stringify(maybeError));
|
|
71
|
+
} catch {
|
|
72
|
+
return new Error(String(maybeError));
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// src/utils/get-relative-path.ts
|
|
77
|
+
function getRootRelativePath(path16, rootPath) {
|
|
78
|
+
const strippedPath = path16.replace(rootPath, "");
|
|
79
|
+
return strippedPath.startsWith("/") ? `(root)${strippedPath}` : `(root)/${strippedPath}`;
|
|
80
|
+
}
|
|
81
|
+
function getIsolateRelativePath(path16, isolatePath) {
|
|
82
|
+
const strippedPath = path16.replace(isolatePath, "");
|
|
83
|
+
return strippedPath.startsWith("/") ? `(isolate)${strippedPath}` : `(isolate)/${strippedPath}`;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// src/utils/inspect-value.ts
|
|
87
|
+
var import_node_util = require("util");
|
|
88
|
+
function inspectValue(value) {
|
|
89
|
+
return (0, import_node_util.inspect)(value, false, 4, true);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// src/utils/is-present.ts
|
|
93
|
+
function isDefined(t) {
|
|
94
|
+
return t !== void 0;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// src/utils/json.ts
|
|
98
|
+
var import_fs_extra = __toESM(require("fs-extra"), 1);
|
|
99
|
+
var import_strip_json_comments = __toESM(require("strip-json-comments"), 1);
|
|
100
|
+
function readTypedJsonSync(filePath) {
|
|
101
|
+
try {
|
|
102
|
+
const rawContent = import_fs_extra.default.readFileSync(filePath, "utf-8");
|
|
103
|
+
const data = JSON.parse((0, import_strip_json_comments.default)(rawContent));
|
|
104
|
+
return data;
|
|
105
|
+
} catch (err) {
|
|
106
|
+
throw new Error(
|
|
107
|
+
`Failed to read JSON from ${filePath}: ${getErrorMessage(err)}`
|
|
108
|
+
);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
async function readTypedJson(filePath) {
|
|
112
|
+
try {
|
|
113
|
+
const rawContent = await import_fs_extra.default.readFile(filePath, "utf-8");
|
|
114
|
+
const data = JSON.parse(rawContent);
|
|
115
|
+
return data;
|
|
116
|
+
} catch (err) {
|
|
117
|
+
throw new Error(
|
|
118
|
+
`Failed to read JSON from ${filePath}: ${getErrorMessage(err)}`
|
|
119
|
+
);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
// src/utils/logger.ts
|
|
124
|
+
var import_chalk = __toESM(require("chalk"), 1);
|
|
125
|
+
var _loggerHandlers = {
|
|
126
|
+
debug(...args) {
|
|
127
|
+
console.log(import_chalk.default.blue("debug"), ...args);
|
|
128
|
+
},
|
|
129
|
+
info(...args) {
|
|
130
|
+
console.log(import_chalk.default.green("info"), ...args);
|
|
131
|
+
},
|
|
132
|
+
warn(...args) {
|
|
133
|
+
console.log(import_chalk.default.yellow("warning"), ...args);
|
|
134
|
+
},
|
|
135
|
+
error(...args) {
|
|
136
|
+
console.log(import_chalk.default.red("error"), ...args);
|
|
137
|
+
}
|
|
138
|
+
};
|
|
139
|
+
var _logger = {
|
|
140
|
+
debug(...args) {
|
|
141
|
+
if (_logLevel === "debug") {
|
|
142
|
+
_loggerHandlers.debug(...args);
|
|
143
|
+
}
|
|
144
|
+
},
|
|
145
|
+
info(...args) {
|
|
146
|
+
if (_logLevel === "debug" || _logLevel === "info") {
|
|
147
|
+
_loggerHandlers.info(...args);
|
|
148
|
+
}
|
|
149
|
+
},
|
|
150
|
+
warn(...args) {
|
|
151
|
+
if (_logLevel === "debug" || _logLevel === "info" || _logLevel === "warn") {
|
|
152
|
+
_loggerHandlers.warn(...args);
|
|
153
|
+
}
|
|
154
|
+
},
|
|
155
|
+
error(...args) {
|
|
156
|
+
_loggerHandlers.error(...args);
|
|
157
|
+
}
|
|
158
|
+
};
|
|
159
|
+
var _logLevel = "info";
|
|
160
|
+
function setLogger(logger) {
|
|
161
|
+
_loggerHandlers = logger;
|
|
162
|
+
return _logger;
|
|
163
|
+
}
|
|
164
|
+
function setLogLevel(logLevel) {
|
|
165
|
+
_logLevel = logLevel;
|
|
166
|
+
return _logger;
|
|
167
|
+
}
|
|
168
|
+
function useLogger() {
|
|
169
|
+
return _logger;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
// src/utils/pack.ts
|
|
173
|
+
var import_fs_extra2 = __toESM(require("fs-extra"), 1);
|
|
174
|
+
var import_node_child_process = require("child_process");
|
|
175
|
+
var import_node_path = __toESM(require("path"), 1);
|
|
176
|
+
async function pack(srcDir, dstDir, usePnpmPack = false) {
|
|
177
|
+
const execOptions = {
|
|
178
|
+
maxBuffer: 10 * 1024 * 1024
|
|
179
|
+
};
|
|
180
|
+
const log = useLogger();
|
|
181
|
+
const previousCwd = process.cwd();
|
|
182
|
+
process.chdir(srcDir);
|
|
183
|
+
const stdout = usePnpmPack ? await new Promise((resolve, reject) => {
|
|
184
|
+
(0, import_node_child_process.exec)(
|
|
185
|
+
`pnpm pack --pack-destination ${dstDir}`,
|
|
186
|
+
execOptions,
|
|
187
|
+
(err, stdout2, stderr) => {
|
|
188
|
+
if (err) {
|
|
189
|
+
log.error(stderr);
|
|
190
|
+
return reject(err);
|
|
191
|
+
}
|
|
192
|
+
resolve(stdout2);
|
|
193
|
+
}
|
|
194
|
+
);
|
|
195
|
+
}) : await new Promise((resolve, reject) => {
|
|
196
|
+
(0, import_node_child_process.exec)(
|
|
197
|
+
`npm pack --pack-destination ${dstDir}`,
|
|
198
|
+
execOptions,
|
|
199
|
+
(err, stdout2) => {
|
|
200
|
+
if (err) {
|
|
201
|
+
return reject(err);
|
|
202
|
+
}
|
|
203
|
+
resolve(stdout2);
|
|
204
|
+
}
|
|
205
|
+
);
|
|
206
|
+
});
|
|
207
|
+
const fileName = import_node_path.default.basename(stdout.trim());
|
|
208
|
+
const filePath = import_node_path.default.join(dstDir, fileName);
|
|
209
|
+
if (!import_fs_extra2.default.existsSync(filePath)) {
|
|
210
|
+
log.error(
|
|
211
|
+
`The response from pack could not be resolved to an existing file: ${filePath}`
|
|
212
|
+
);
|
|
213
|
+
} else {
|
|
214
|
+
log.debug(`Packed (temp)/${fileName}`);
|
|
215
|
+
}
|
|
216
|
+
process.chdir(previousCwd);
|
|
217
|
+
return filePath;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
// src/utils/unpack.ts
|
|
221
|
+
var import_fs_extra3 = __toESM(require("fs-extra"), 1);
|
|
222
|
+
var import_tar_fs = __toESM(require("tar-fs"), 1);
|
|
223
|
+
var import_zlib = require("zlib");
|
|
224
|
+
async function unpack(filePath, unpackDir) {
|
|
225
|
+
await new Promise((resolve, reject) => {
|
|
226
|
+
import_fs_extra3.default.createReadStream(filePath).pipe((0, import_zlib.createGunzip)()).pipe(import_tar_fs.default.extract(unpackDir)).on("finish", () => resolve()).on("error", (err) => reject(err));
|
|
227
|
+
});
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
// src/utils/yaml.ts
|
|
231
|
+
var import_fs_extra4 = __toESM(require("fs-extra"), 1);
|
|
232
|
+
var import_yaml = __toESM(require("yaml"), 1);
|
|
233
|
+
function readTypedYamlSync(filePath) {
|
|
234
|
+
try {
|
|
235
|
+
const rawContent = import_fs_extra4.default.readFileSync(filePath, "utf-8");
|
|
236
|
+
const data = import_yaml.default.parse(rawContent);
|
|
237
|
+
return data;
|
|
238
|
+
} catch (err) {
|
|
239
|
+
throw new Error(
|
|
240
|
+
`Failed to read YAML from ${filePath}: ${getErrorMessage(err)}`
|
|
241
|
+
);
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
// src/helpers/adapt-internal-package-manifests.ts
|
|
246
|
+
var import_fs_extra8 = __toESM(require("fs-extra"), 1);
|
|
247
|
+
var import_node_path8 = __toESM(require("path"), 1);
|
|
248
|
+
var import_ramda5 = require("ramda");
|
|
249
|
+
|
|
250
|
+
// src/helpers/adapt-manifest-internal-deps.ts
|
|
251
|
+
var import_ramda = require("ramda");
|
|
252
|
+
|
|
253
|
+
// src/helpers/patch-internal-entries.ts
|
|
254
|
+
var import_node_path2 = __toESM(require("path"), 1);
|
|
255
|
+
function patchInternalEntries(dependencies, packagesRegistry, parentRootRelativeDir) {
|
|
256
|
+
const log = useLogger();
|
|
257
|
+
const allWorkspacePackageNames = Object.keys(packagesRegistry);
|
|
258
|
+
return Object.fromEntries(
|
|
259
|
+
Object.entries(dependencies).map(([key, value]) => {
|
|
260
|
+
if (allWorkspacePackageNames.includes(key)) {
|
|
261
|
+
const def = packagesRegistry[key];
|
|
262
|
+
const relativePath = parentRootRelativeDir ? import_node_path2.default.relative(parentRootRelativeDir, `./${def.rootRelativeDir}`) : `./${def.rootRelativeDir}`;
|
|
263
|
+
const linkPath = `file:${relativePath}`;
|
|
264
|
+
log.debug(`Linking dependency ${key} to ${linkPath}`);
|
|
265
|
+
return [key, linkPath];
|
|
266
|
+
} else {
|
|
267
|
+
return [key, value];
|
|
268
|
+
}
|
|
269
|
+
})
|
|
270
|
+
);
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
// src/helpers/adapt-manifest-internal-deps.ts
|
|
274
|
+
function adaptManifestInternalDeps({
|
|
275
|
+
manifest,
|
|
276
|
+
packagesRegistry,
|
|
277
|
+
parentRootRelativeDir
|
|
278
|
+
}, opts = {}) {
|
|
279
|
+
return Object.assign(
|
|
280
|
+
(0, import_ramda.omit)(["devDependencies"], manifest),
|
|
281
|
+
filterObjectUndefined({
|
|
282
|
+
dependencies: manifest.dependencies ? patchInternalEntries(
|
|
283
|
+
manifest.dependencies,
|
|
284
|
+
packagesRegistry,
|
|
285
|
+
parentRootRelativeDir
|
|
286
|
+
) : void 0,
|
|
287
|
+
devDependencies: opts.includeDevDependencies && manifest.devDependencies ? patchInternalEntries(
|
|
288
|
+
manifest.devDependencies,
|
|
289
|
+
packagesRegistry,
|
|
290
|
+
parentRootRelativeDir
|
|
291
|
+
) : void 0
|
|
292
|
+
})
|
|
293
|
+
);
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
// src/helpers/config.ts
|
|
297
|
+
var import_fs_extra5 = __toESM(require("fs-extra"), 1);
|
|
298
|
+
var import_node_assert = __toESM(require("assert"), 1);
|
|
299
|
+
var import_node_path3 = __toESM(require("path"), 1);
|
|
300
|
+
var import_ramda2 = require("ramda");
|
|
301
|
+
var configDefaults = {
|
|
302
|
+
buildDirName: void 0,
|
|
303
|
+
includeDevDependencies: false,
|
|
304
|
+
isolateDirName: "isolate",
|
|
305
|
+
logLevel: "info",
|
|
306
|
+
targetPackagePath: void 0,
|
|
307
|
+
tsconfigPath: "./tsconfig.json",
|
|
308
|
+
workspacePackages: void 0,
|
|
309
|
+
workspaceRoot: "../..",
|
|
310
|
+
excludeLockfile: false,
|
|
311
|
+
avoidPnpmPack: false
|
|
312
|
+
};
|
|
313
|
+
var _resolvedConfig;
|
|
314
|
+
var _user_defined_config;
|
|
315
|
+
var validConfigKeys = Object.keys(configDefaults);
|
|
316
|
+
var CONFIG_FILE_NAME = "isolate.config.json";
|
|
317
|
+
function setUserConfig(config) {
|
|
318
|
+
_user_defined_config = config;
|
|
319
|
+
if (config.logLevel) {
|
|
320
|
+
setLogLevel(config.logLevel);
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
function useConfig() {
|
|
324
|
+
if (_resolvedConfig) {
|
|
325
|
+
return _resolvedConfig;
|
|
326
|
+
} else {
|
|
327
|
+
throw new Error("Called useConfig before config was made available");
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
function resolveConfig() {
|
|
331
|
+
if (_resolvedConfig) {
|
|
332
|
+
return _resolvedConfig;
|
|
333
|
+
}
|
|
334
|
+
setLogLevel(process.env.DEBUG_ISOLATE_CONFIG ? "debug" : "info");
|
|
335
|
+
const log = useLogger();
|
|
336
|
+
const configFilePath = import_node_path3.default.join(process.cwd(), CONFIG_FILE_NAME);
|
|
337
|
+
if (_user_defined_config) {
|
|
338
|
+
log.debug(`Using user defined config:`, inspectValue(_user_defined_config));
|
|
339
|
+
} else {
|
|
340
|
+
log.debug(`Attempting to load config from ${configFilePath}`);
|
|
341
|
+
_user_defined_config = import_fs_extra5.default.existsSync(configFilePath) ? readTypedJsonSync(configFilePath) : {};
|
|
342
|
+
}
|
|
343
|
+
const foreignKeys = Object.keys(_user_defined_config).filter(
|
|
344
|
+
(key) => !validConfigKeys.includes(key)
|
|
345
|
+
);
|
|
346
|
+
if (!(0, import_ramda2.isEmpty)(foreignKeys)) {
|
|
347
|
+
log.warn(`Found invalid config settings:`, foreignKeys.join(", "));
|
|
348
|
+
}
|
|
349
|
+
const config = Object.assign(
|
|
350
|
+
{},
|
|
351
|
+
configDefaults,
|
|
352
|
+
_user_defined_config
|
|
353
|
+
);
|
|
354
|
+
log.debug("Using configuration:", inspectValue(config));
|
|
355
|
+
_resolvedConfig = config;
|
|
356
|
+
return config;
|
|
357
|
+
}
|
|
358
|
+
function getUserDefinedConfig() {
|
|
359
|
+
(0, import_node_assert.default)(
|
|
360
|
+
_user_defined_config,
|
|
361
|
+
"Called getUserDefinedConfig before user config was made available"
|
|
362
|
+
);
|
|
363
|
+
return _user_defined_config;
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
// src/helpers/detect-package-manager.ts
|
|
367
|
+
var import_fs_extra7 = __toESM(require("fs-extra"), 1);
|
|
368
|
+
var import_node_assert3 = __toESM(require("assert"), 1);
|
|
369
|
+
var import_node_child_process2 = require("child_process");
|
|
370
|
+
var import_node_path7 = __toESM(require("path"), 1);
|
|
371
|
+
|
|
372
|
+
// src/helpers/process-lockfile.ts
|
|
373
|
+
var import_fs_extra6 = __toESM(require("fs-extra"), 1);
|
|
374
|
+
var import_node_path6 = __toESM(require("path"), 1);
|
|
375
|
+
var import_ramda4 = require("ramda");
|
|
376
|
+
|
|
377
|
+
// src/helpers/generate-npm-lockfile.ts
|
|
378
|
+
var import_arborist = __toESM(require("@npmcli/arborist"), 1);
|
|
379
|
+
var import_promises = __toESM(require("fs/promises"), 1);
|
|
380
|
+
var import_node_path4 = __toESM(require("path"), 1);
|
|
381
|
+
|
|
382
|
+
// src/helpers/generate-pnpm-lockfile.ts
|
|
383
|
+
var import_lockfile_file = require("@pnpm/lockfile-file");
|
|
384
|
+
var import_node_assert2 = __toESM(require("assert"), 1);
|
|
385
|
+
var import_node_path5 = __toESM(require("path"), 1);
|
|
386
|
+
var import_ramda3 = require("ramda");
|
|
387
|
+
async function generatePnpmLockfile({
|
|
388
|
+
workspaceRootDir,
|
|
389
|
+
targetPackageDir,
|
|
390
|
+
isolateDir,
|
|
391
|
+
internalDepPackageNames,
|
|
392
|
+
packagesRegistry
|
|
393
|
+
}) {
|
|
394
|
+
const { includeDevDependencies } = useConfig();
|
|
395
|
+
const log = useLogger();
|
|
396
|
+
log.debug("Generating PNPM lockfile");
|
|
397
|
+
const lockfile = await (0, import_lockfile_file.readWantedLockfile)(workspaceRootDir, {
|
|
398
|
+
ignoreIncompatible: false
|
|
399
|
+
});
|
|
400
|
+
(0, import_node_assert2.default)(lockfile, "No lockfile found");
|
|
401
|
+
const targetImporterId = (0, import_lockfile_file.getLockfileImporterId)(
|
|
402
|
+
workspaceRootDir,
|
|
403
|
+
targetPackageDir
|
|
404
|
+
);
|
|
405
|
+
const directoryByPackageName = Object.fromEntries(
|
|
406
|
+
internalDepPackageNames.map((name) => {
|
|
407
|
+
const pkg = packagesRegistry[name];
|
|
408
|
+
(0, import_node_assert2.default)(pkg, `Package ${name} not found in packages registry`);
|
|
409
|
+
return [name, pkg.rootRelativeDir];
|
|
410
|
+
})
|
|
411
|
+
);
|
|
412
|
+
const relevantImporterIds = [
|
|
413
|
+
targetImporterId,
|
|
414
|
+
/**
|
|
415
|
+
* The directory paths happen to correspond with what PNPM calls the
|
|
416
|
+
* importer ids in the context of a lockfile.
|
|
417
|
+
*/
|
|
418
|
+
...Object.values(directoryByPackageName)
|
|
419
|
+
];
|
|
420
|
+
log.debug("Relevant importer ids:", relevantImporterIds);
|
|
421
|
+
lockfile.importers = Object.fromEntries(
|
|
422
|
+
Object.entries((0, import_ramda3.pick)(relevantImporterIds, lockfile.importers)).map(
|
|
423
|
+
([importerId, importer]) => {
|
|
424
|
+
if (importerId === targetImporterId) {
|
|
425
|
+
log.debug("Setting target package importer on root");
|
|
426
|
+
return [
|
|
427
|
+
".",
|
|
428
|
+
pnpmMapImporter(importer, {
|
|
429
|
+
includeDevDependencies,
|
|
430
|
+
directoryByPackageName
|
|
431
|
+
})
|
|
432
|
+
];
|
|
433
|
+
}
|
|
434
|
+
log.debug("Setting internal package importer:", importerId);
|
|
435
|
+
return [
|
|
436
|
+
importerId,
|
|
437
|
+
pnpmMapImporter(importer, {
|
|
438
|
+
includeDevDependencies,
|
|
439
|
+
directoryByPackageName
|
|
440
|
+
})
|
|
441
|
+
];
|
|
442
|
+
}
|
|
443
|
+
)
|
|
444
|
+
);
|
|
445
|
+
await (0, import_lockfile_file.writeWantedLockfile)(isolateDir, lockfile);
|
|
446
|
+
log.debug("Created lockfile at", import_node_path5.default.join(isolateDir, "pnpm-lock.yaml"));
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
// src/helpers/process-lockfile.ts
|
|
450
|
+
function getLockfileFileName(name) {
|
|
451
|
+
switch (name) {
|
|
452
|
+
case "pnpm":
|
|
453
|
+
return "pnpm-lock.yaml";
|
|
454
|
+
case "yarn":
|
|
455
|
+
return "yarn.lock";
|
|
456
|
+
case "npm":
|
|
457
|
+
return "package-lock.json";
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
function pnpmMapImporter({ dependencies, devDependencies, ...rest }, {
|
|
461
|
+
includeDevDependencies,
|
|
462
|
+
directoryByPackageName
|
|
463
|
+
}) {
|
|
464
|
+
return {
|
|
465
|
+
dependencies: dependencies ? pnpmMapDependenciesLinks(dependencies, directoryByPackageName) : void 0,
|
|
466
|
+
devDependencies: includeDevDependencies && devDependencies ? pnpmMapDependenciesLinks(devDependencies, directoryByPackageName) : void 0,
|
|
467
|
+
...rest
|
|
468
|
+
};
|
|
469
|
+
}
|
|
470
|
+
function pnpmMapDependenciesLinks(def, directoryByPackageName) {
|
|
471
|
+
return (0, import_ramda4.mapObjIndexed)(
|
|
472
|
+
(version, name) => version.startsWith("link:") ? `link:./${directoryByPackageName[name]}` : version,
|
|
473
|
+
def
|
|
474
|
+
);
|
|
475
|
+
}
|
|
476
|
+
async function processLockfile({
|
|
477
|
+
workspaceRootDir,
|
|
478
|
+
packagesRegistry,
|
|
479
|
+
isolateDir,
|
|
480
|
+
internalDepPackageNames,
|
|
481
|
+
targetPackageDir,
|
|
482
|
+
targetPackageName
|
|
483
|
+
}) {
|
|
484
|
+
const log = useLogger();
|
|
485
|
+
const { name } = usePackageManager();
|
|
486
|
+
const fileName = getLockfileFileName(name);
|
|
487
|
+
const lockfileSrcPath = import_node_path6.default.join(workspaceRootDir, fileName);
|
|
488
|
+
const lockfileDstPath = import_node_path6.default.join(isolateDir, fileName);
|
|
489
|
+
switch (name) {
|
|
490
|
+
case "npm": {
|
|
491
|
+
const shrinkwrapSrcPath = import_node_path6.default.join(
|
|
492
|
+
workspaceRootDir,
|
|
493
|
+
"npm-shrinkwrap.json"
|
|
494
|
+
);
|
|
495
|
+
const shrinkwrapDstPath = import_node_path6.default.join(isolateDir, "npm-shrinkwrap.json");
|
|
496
|
+
if (import_fs_extra6.default.existsSync(shrinkwrapSrcPath)) {
|
|
497
|
+
import_fs_extra6.default.copyFileSync(shrinkwrapSrcPath, shrinkwrapDstPath);
|
|
498
|
+
log.debug("Copied shrinkwrap to", shrinkwrapDstPath);
|
|
499
|
+
} else {
|
|
500
|
+
import_fs_extra6.default.copyFileSync(lockfileSrcPath, lockfileDstPath);
|
|
501
|
+
log.debug("Copied lockfile to", lockfileDstPath);
|
|
502
|
+
}
|
|
503
|
+
if (false) {
|
|
504
|
+
await generateNpmLockfile({
|
|
505
|
+
workspaceRootDir,
|
|
506
|
+
targetPackageName,
|
|
507
|
+
isolateDir,
|
|
508
|
+
packagesRegistry
|
|
509
|
+
});
|
|
510
|
+
}
|
|
511
|
+
break;
|
|
512
|
+
}
|
|
513
|
+
case "yarn": {
|
|
514
|
+
import_fs_extra6.default.copyFileSync(lockfileSrcPath, lockfileDstPath);
|
|
515
|
+
log.debug("Copied lockfile to", lockfileDstPath);
|
|
516
|
+
break;
|
|
517
|
+
}
|
|
518
|
+
case "pnpm": {
|
|
519
|
+
await generatePnpmLockfile({
|
|
520
|
+
workspaceRootDir,
|
|
521
|
+
targetPackageDir,
|
|
522
|
+
isolateDir,
|
|
523
|
+
internalDepPackageNames,
|
|
524
|
+
packagesRegistry
|
|
525
|
+
});
|
|
526
|
+
break;
|
|
527
|
+
}
|
|
528
|
+
default:
|
|
529
|
+
log.warn(`Unexpected package manager ${name}`);
|
|
530
|
+
}
|
|
531
|
+
}
|
|
532
|
+
|
|
533
|
+
// src/helpers/detect-package-manager.ts
|
|
534
|
+
var supportedPackageManagerNames = ["pnpm", "yarn", "npm"];
|
|
535
|
+
var packageManager;
|
|
536
|
+
function detectPackageManager(workspaceRoot) {
|
|
537
|
+
packageManager = inferFromManifest(workspaceRoot) ?? inferFromFiles(workspaceRoot);
|
|
538
|
+
return packageManager;
|
|
539
|
+
}
|
|
540
|
+
function inferFromManifest(workspaceRoot) {
|
|
541
|
+
const log = useLogger();
|
|
542
|
+
const rootManifest = readTypedJsonSync(
|
|
543
|
+
import_node_path7.default.join(workspaceRoot, "package.json")
|
|
544
|
+
);
|
|
545
|
+
if (!rootManifest.packageManager) {
|
|
546
|
+
log.debug("No packageManager field found in root manifest");
|
|
547
|
+
return;
|
|
548
|
+
}
|
|
549
|
+
const [name, version = "*"] = rootManifest.packageManager.split("@");
|
|
550
|
+
(0, import_node_assert3.default)(
|
|
551
|
+
supportedPackageManagerNames.includes(name),
|
|
552
|
+
`Package manager "${name}" is not currently supported`
|
|
553
|
+
);
|
|
554
|
+
const lockfileName = getLockfileFileName(name);
|
|
555
|
+
(0, import_node_assert3.default)(
|
|
556
|
+
import_fs_extra7.default.existsSync(import_node_path7.default.join(workspaceRoot, lockfileName)),
|
|
557
|
+
`Manifest declares ${name} to be the packageManager, but failed to find ${lockfileName} in workspace root`
|
|
558
|
+
);
|
|
559
|
+
return { name, version };
|
|
560
|
+
}
|
|
561
|
+
function inferFromFiles(workspaceRoot) {
|
|
562
|
+
for (const name of supportedPackageManagerNames) {
|
|
563
|
+
const lockfileName = getLockfileFileName(name);
|
|
564
|
+
if (import_fs_extra7.default.existsSync(import_node_path7.default.join(workspaceRoot, lockfileName))) {
|
|
565
|
+
return { name, version: getVersion(name) };
|
|
566
|
+
}
|
|
567
|
+
}
|
|
568
|
+
if (import_fs_extra7.default.existsSync(import_node_path7.default.join(workspaceRoot, "npm-shrinkwrap.json"))) {
|
|
569
|
+
return { name: "npm", version: getVersion("npm") };
|
|
570
|
+
}
|
|
571
|
+
throw new Error(`Failed to detect package manager`);
|
|
572
|
+
}
|
|
573
|
+
function getVersion(packageManagerName) {
|
|
574
|
+
const buffer = (0, import_node_child_process2.execSync)(`${packageManagerName} --version`);
|
|
575
|
+
return buffer.toString().trim();
|
|
576
|
+
}
|
|
577
|
+
function usePackageManager() {
|
|
578
|
+
if (!packageManager) {
|
|
579
|
+
throw Error(
|
|
580
|
+
"No package manager detected. Make sure to call detectPackageManager() before usePackageManager()"
|
|
581
|
+
);
|
|
582
|
+
}
|
|
583
|
+
return packageManager;
|
|
584
|
+
}
|
|
585
|
+
|
|
586
|
+
// src/helpers/adapt-internal-package-manifests.ts
|
|
587
|
+
async function adaptInternalPackageManifests(internalPackageNames, packagesRegistry, isolateDir) {
|
|
588
|
+
const packageManager2 = usePackageManager();
|
|
589
|
+
const { includeDevDependencies } = useConfig();
|
|
590
|
+
await Promise.all(
|
|
591
|
+
internalPackageNames.map(async (packageName) => {
|
|
592
|
+
const { manifest, rootRelativeDir } = packagesRegistry[packageName];
|
|
593
|
+
const outputManifest = packageManager2.name === "pnpm" ? Object.assign(
|
|
594
|
+
/**
|
|
595
|
+
* For internal dependencies we want to omit the peerDependencies,
|
|
596
|
+
* because installing these is the responsibility of the consuming
|
|
597
|
+
* app / service, and otherwise the frozen lockfile install will
|
|
598
|
+
* error since the package file contains something that is not
|
|
599
|
+
* referenced in the lockfile.
|
|
600
|
+
*/
|
|
601
|
+
(0, import_ramda5.omit)(["devDependencies", "peerDependencies"], manifest),
|
|
602
|
+
{
|
|
603
|
+
dependencies: manifest.dependencies,
|
|
604
|
+
devDependencies: includeDevDependencies ? manifest.devDependencies : void 0
|
|
605
|
+
}
|
|
606
|
+
) : adaptManifestInternalDeps(
|
|
607
|
+
{
|
|
608
|
+
manifest,
|
|
609
|
+
packagesRegistry,
|
|
610
|
+
parentRootRelativeDir: rootRelativeDir
|
|
611
|
+
},
|
|
612
|
+
{ includeDevDependencies }
|
|
613
|
+
);
|
|
614
|
+
await import_fs_extra8.default.writeFile(
|
|
615
|
+
import_node_path8.default.join(isolateDir, rootRelativeDir, "package.json"),
|
|
616
|
+
JSON.stringify(outputManifest, null, 2)
|
|
617
|
+
);
|
|
618
|
+
})
|
|
619
|
+
);
|
|
620
|
+
}
|
|
621
|
+
|
|
622
|
+
// src/helpers/adapt-target-package-manifest.ts
|
|
623
|
+
var import_fs_extra9 = __toESM(require("fs-extra"), 1);
|
|
624
|
+
var import_node_path9 = __toESM(require("path"), 1);
|
|
625
|
+
var import_ramda6 = require("ramda");
|
|
626
|
+
async function adaptTargetPackageManifest(manifest, packagesRegistry, isolateDir) {
|
|
627
|
+
const packageManager2 = usePackageManager();
|
|
628
|
+
const { includeDevDependencies } = useConfig();
|
|
629
|
+
const outputManifest = packageManager2.name === "pnpm" ? Object.assign((0, import_ramda6.omit)(["devDependencies", "scripts"], manifest), {
|
|
630
|
+
devDependencies: includeDevDependencies ? manifest.devDependencies : void 0
|
|
631
|
+
}) : adaptManifestInternalDeps(
|
|
632
|
+
{
|
|
633
|
+
manifest,
|
|
634
|
+
packagesRegistry
|
|
635
|
+
},
|
|
636
|
+
{ includeDevDependencies }
|
|
637
|
+
);
|
|
638
|
+
await import_fs_extra9.default.writeFile(
|
|
639
|
+
import_node_path9.default.join(isolateDir, "package.json"),
|
|
640
|
+
JSON.stringify(outputManifest, null, 2)
|
|
641
|
+
);
|
|
642
|
+
}
|
|
643
|
+
|
|
644
|
+
// src/helpers/create-packages-registry.ts
|
|
645
|
+
var import_fs_extra10 = __toESM(require("fs-extra"), 1);
|
|
646
|
+
var import_glob = require("glob");
|
|
647
|
+
var import_node_path11 = __toESM(require("path"), 1);
|
|
648
|
+
|
|
649
|
+
// src/helpers/find-packages-globs.ts
|
|
650
|
+
var import_node_assert4 = __toESM(require("assert"), 1);
|
|
651
|
+
var import_node_path10 = __toESM(require("path"), 1);
|
|
652
|
+
function findPackagesGlobs(workspaceRootDir) {
|
|
653
|
+
const log = useLogger();
|
|
654
|
+
const packageManager2 = usePackageManager();
|
|
655
|
+
switch (packageManager2.name) {
|
|
656
|
+
case "pnpm": {
|
|
657
|
+
const { packages: globs } = readTypedYamlSync(
|
|
658
|
+
import_node_path10.default.join(workspaceRootDir, "pnpm-workspace.yaml")
|
|
659
|
+
);
|
|
660
|
+
log.debug("Detected pnpm packages globs:", inspectValue(globs));
|
|
661
|
+
return globs;
|
|
662
|
+
}
|
|
663
|
+
case "yarn":
|
|
664
|
+
case "npm": {
|
|
665
|
+
const workspaceRootManifestPath = import_node_path10.default.join(
|
|
666
|
+
workspaceRootDir,
|
|
667
|
+
"package.json"
|
|
668
|
+
);
|
|
669
|
+
const { workspaces } = readTypedJsonSync(
|
|
670
|
+
workspaceRootManifestPath
|
|
671
|
+
);
|
|
672
|
+
if (!workspaces) {
|
|
673
|
+
throw new Error(
|
|
674
|
+
`No workspaces field found in ${workspaceRootManifestPath}`
|
|
675
|
+
);
|
|
676
|
+
}
|
|
677
|
+
if (Array.isArray(workspaces)) {
|
|
678
|
+
return workspaces;
|
|
679
|
+
} else {
|
|
680
|
+
const workspacesObject = workspaces;
|
|
681
|
+
(0, import_node_assert4.default)(
|
|
682
|
+
workspacesObject.packages,
|
|
683
|
+
"workspaces.packages must be an array"
|
|
684
|
+
);
|
|
685
|
+
return workspacesObject.packages;
|
|
686
|
+
}
|
|
687
|
+
}
|
|
688
|
+
}
|
|
689
|
+
}
|
|
690
|
+
|
|
691
|
+
// src/helpers/create-packages-registry.ts
|
|
692
|
+
async function createPackagesRegistry(workspaceRootDir, workspacePackagesOverride) {
|
|
693
|
+
const log = useLogger();
|
|
694
|
+
if (workspacePackagesOverride) {
|
|
695
|
+
log.debug(
|
|
696
|
+
`Override workspace packages via config: ${workspacePackagesOverride}`
|
|
697
|
+
);
|
|
698
|
+
}
|
|
699
|
+
const packagesGlobs = workspacePackagesOverride ?? findPackagesGlobs(workspaceRootDir);
|
|
700
|
+
const cwd = process.cwd();
|
|
701
|
+
process.chdir(workspaceRootDir);
|
|
702
|
+
const allPackages = packagesGlobs.flatMap((glob) => (0, import_glob.globSync)(glob)).filter((dir) => import_fs_extra10.default.lstatSync(dir).isDirectory());
|
|
703
|
+
const registry = (await Promise.all(
|
|
704
|
+
allPackages.map(async (rootRelativeDir) => {
|
|
705
|
+
const manifestPath = import_node_path11.default.join(rootRelativeDir, "package.json");
|
|
706
|
+
if (!import_fs_extra10.default.existsSync(manifestPath)) {
|
|
707
|
+
log.warn(
|
|
708
|
+
`Ignoring directory ./${rootRelativeDir} because it does not contain a package.json file`
|
|
709
|
+
);
|
|
710
|
+
return;
|
|
711
|
+
} else {
|
|
712
|
+
log.debug(`Registering package ./${rootRelativeDir}`);
|
|
713
|
+
const manifest = await readTypedJson(
|
|
714
|
+
import_node_path11.default.join(rootRelativeDir, "package.json")
|
|
715
|
+
);
|
|
716
|
+
return {
|
|
717
|
+
manifest,
|
|
718
|
+
rootRelativeDir,
|
|
719
|
+
absoluteDir: import_node_path11.default.join(workspaceRootDir, rootRelativeDir)
|
|
720
|
+
};
|
|
721
|
+
}
|
|
722
|
+
})
|
|
723
|
+
)).reduce((acc, info) => {
|
|
724
|
+
if (info) {
|
|
725
|
+
acc[info.manifest.name] = info;
|
|
726
|
+
}
|
|
727
|
+
return acc;
|
|
728
|
+
}, {});
|
|
729
|
+
process.chdir(cwd);
|
|
730
|
+
return registry;
|
|
731
|
+
}
|
|
732
|
+
|
|
733
|
+
// src/helpers/get-build-output-dir.ts
|
|
734
|
+
var import_fs_extra11 = __toESM(require("fs-extra"), 1);
|
|
735
|
+
var import_node_path12 = __toESM(require("path"), 1);
|
|
736
|
+
var import_outdent = __toESM(require("outdent"), 1);
|
|
737
|
+
async function getBuildOutputDir(targetPackageDir) {
|
|
738
|
+
const config = useConfig();
|
|
739
|
+
const log = useLogger();
|
|
740
|
+
if (config.buildDirName) {
|
|
741
|
+
log.debug("Using buildDirName from config:", config.buildDirName);
|
|
742
|
+
return import_node_path12.default.join(targetPackageDir, config.buildDirName);
|
|
743
|
+
}
|
|
744
|
+
const tsconfigPath = import_node_path12.default.join(targetPackageDir, config.tsconfigPath);
|
|
745
|
+
if (import_fs_extra11.default.existsSync(tsconfigPath)) {
|
|
746
|
+
log.debug("Found tsconfig at:", config.tsconfigPath);
|
|
747
|
+
const tsconfig = await readTypedJson(tsconfigPath);
|
|
748
|
+
const outDir = tsconfig.compilerOptions?.outDir;
|
|
749
|
+
if (outDir) {
|
|
750
|
+
return import_node_path12.default.join(targetPackageDir, outDir);
|
|
751
|
+
} else {
|
|
752
|
+
throw new Error(import_outdent.default`
|
|
753
|
+
Failed to find outDir in tsconfig. If you are executing isolate from the root of a monorepo you should specify the buildDirName in isolate.config.json.
|
|
754
|
+
`);
|
|
755
|
+
}
|
|
756
|
+
} else {
|
|
757
|
+
log.warn("Failed to find tsconfig at:", tsconfigPath);
|
|
758
|
+
throw new Error(import_outdent.default`
|
|
759
|
+
Failed to infer the build output directory from either the isolate config buildDirName or a Typescript config file. See the documentation on how to configure one of these options.
|
|
760
|
+
`);
|
|
761
|
+
}
|
|
762
|
+
}
|
|
763
|
+
|
|
764
|
+
// src/helpers/list-internal-packages.ts
|
|
765
|
+
var import_ramda7 = require("ramda");
|
|
766
|
+
function listInternalPackages(manifest, packagesRegistry, { includeDevDependencies = false } = {}) {
|
|
767
|
+
const allWorkspacePackageNames = Object.keys(packagesRegistry);
|
|
768
|
+
const internalPackageNames = (includeDevDependencies ? [
|
|
769
|
+
...Object.keys(manifest.dependencies ?? {}),
|
|
770
|
+
...Object.keys(manifest.devDependencies ?? {})
|
|
771
|
+
] : Object.keys(manifest.dependencies ?? {})).filter((name) => allWorkspacePackageNames.includes(name));
|
|
772
|
+
const nestedInternalPackageNames = internalPackageNames.flatMap(
|
|
773
|
+
(packageName) => listInternalPackages(
|
|
774
|
+
packagesRegistry[packageName].manifest,
|
|
775
|
+
packagesRegistry,
|
|
776
|
+
{ includeDevDependencies }
|
|
777
|
+
)
|
|
778
|
+
);
|
|
779
|
+
return (0, import_ramda7.uniq)(internalPackageNames.concat(nestedInternalPackageNames));
|
|
780
|
+
}
|
|
781
|
+
|
|
782
|
+
// src/helpers/pack-dependencies.ts
|
|
783
|
+
var import_node_assert5 = __toESM(require("assert"), 1);
|
|
784
|
+
async function packDependencies({
|
|
785
|
+
/** All packages found in the monorepo by workspaces declaration */
|
|
786
|
+
packagesRegistry,
|
|
787
|
+
/** The dependencies that appear to be internal packages */
|
|
788
|
+
internalPackageNames,
|
|
789
|
+
/**
|
|
790
|
+
* The directory where the isolated package and all its dependencies will end
|
|
791
|
+
* up. This is also the directory from where the package will be deployed. By
|
|
792
|
+
* default it is a subfolder in targetPackageDir called "isolate" but you can
|
|
793
|
+
* configure it.
|
|
794
|
+
*/
|
|
795
|
+
packDestinationDir
|
|
796
|
+
}) {
|
|
797
|
+
const config = useConfig();
|
|
798
|
+
const log = useLogger();
|
|
799
|
+
const packedFileByName = {};
|
|
800
|
+
const { name, version } = usePackageManager();
|
|
801
|
+
const versionMajor = parseInt(version.split(".")[0], 10);
|
|
802
|
+
const usePnpmPack = !config.avoidPnpmPack && name === "pnpm" && versionMajor >= 8;
|
|
803
|
+
if (usePnpmPack) {
|
|
804
|
+
log.debug("Using PNPM pack instead of NPM pack");
|
|
805
|
+
}
|
|
806
|
+
for (const dependency of internalPackageNames) {
|
|
807
|
+
const def = packagesRegistry[dependency];
|
|
808
|
+
(0, import_node_assert5.default)(dependency, `Failed to find package definition for ${dependency}`);
|
|
809
|
+
const { name: name2 } = def.manifest;
|
|
810
|
+
if (packedFileByName[name2]) {
|
|
811
|
+
log.debug(`Skipping ${name2} because it has already been packed`);
|
|
812
|
+
continue;
|
|
813
|
+
}
|
|
814
|
+
packedFileByName[name2] = await pack(
|
|
815
|
+
def.absoluteDir,
|
|
816
|
+
packDestinationDir,
|
|
817
|
+
usePnpmPack
|
|
818
|
+
);
|
|
819
|
+
}
|
|
820
|
+
return packedFileByName;
|
|
821
|
+
}
|
|
822
|
+
|
|
823
|
+
// src/helpers/process-build-output-files.ts
|
|
824
|
+
var import_fs_extra12 = __toESM(require("fs-extra"), 1);
|
|
825
|
+
var import_node_path13 = __toESM(require("path"), 1);
|
|
826
|
+
var TIMEOUT_MS = 5e3;
|
|
827
|
+
async function processBuildOutputFiles({
|
|
828
|
+
targetPackageDir,
|
|
829
|
+
tmpDir,
|
|
830
|
+
isolateDir
|
|
831
|
+
}) {
|
|
832
|
+
const log = useLogger();
|
|
833
|
+
const packedFilePath = await pack(targetPackageDir, tmpDir);
|
|
834
|
+
const unpackDir = import_node_path13.default.join(tmpDir, "target");
|
|
835
|
+
const now = Date.now();
|
|
836
|
+
let isWaitingYet = false;
|
|
837
|
+
while (!import_fs_extra12.default.existsSync(packedFilePath) && Date.now() - now < TIMEOUT_MS) {
|
|
838
|
+
if (!isWaitingYet) {
|
|
839
|
+
log.debug(`Waiting for ${packedFilePath} to become available...`);
|
|
840
|
+
}
|
|
841
|
+
isWaitingYet = true;
|
|
842
|
+
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
843
|
+
}
|
|
844
|
+
await unpack(packedFilePath, unpackDir);
|
|
845
|
+
await import_fs_extra12.default.copy(import_node_path13.default.join(unpackDir, "package"), isolateDir);
|
|
846
|
+
}
|
|
847
|
+
|
|
848
|
+
// src/helpers/unpack-dependencies.ts
|
|
849
|
+
var import_fs_extra13 = __toESM(require("fs-extra"), 1);
|
|
850
|
+
var import_node_path14 = __toESM(require("path"), 1);
|
|
851
|
+
async function unpackDependencies(packedFilesByName, packagesRegistry, tmpDir, isolateDir) {
|
|
852
|
+
const log = useLogger();
|
|
853
|
+
await Promise.all(
|
|
854
|
+
Object.entries(packedFilesByName).map(async ([packageName, filePath]) => {
|
|
855
|
+
const dir = packagesRegistry[packageName].rootRelativeDir;
|
|
856
|
+
const unpackDir = (0, import_node_path14.join)(tmpDir, dir);
|
|
857
|
+
log.debug("Unpacking", `(temp)/${import_node_path14.default.basename(filePath)}`);
|
|
858
|
+
await unpack(filePath, unpackDir);
|
|
859
|
+
const destinationDir = (0, import_node_path14.join)(isolateDir, dir);
|
|
860
|
+
await import_fs_extra13.default.ensureDir(destinationDir);
|
|
861
|
+
await import_fs_extra13.default.move((0, import_node_path14.join)(unpackDir, "package"), destinationDir, {
|
|
862
|
+
overwrite: true
|
|
863
|
+
});
|
|
864
|
+
log.debug(
|
|
865
|
+
`Moved package files to ${getIsolateRelativePath(
|
|
866
|
+
destinationDir,
|
|
867
|
+
isolateDir
|
|
868
|
+
)}`
|
|
869
|
+
);
|
|
870
|
+
})
|
|
871
|
+
);
|
|
872
|
+
}
|
|
873
|
+
|
|
874
|
+
// src/isolate.ts
|
|
875
|
+
var __dirname = getDirname(importMetaUrl);
|
|
876
|
+
async function isolate(options = {}) {
|
|
877
|
+
if (options.logger) {
|
|
878
|
+
setLogger(options.logger);
|
|
879
|
+
}
|
|
880
|
+
if (options.config) {
|
|
881
|
+
setUserConfig(options.config);
|
|
882
|
+
}
|
|
883
|
+
const config = resolveConfig();
|
|
884
|
+
setLogLevel(config.logLevel);
|
|
885
|
+
const log = useLogger();
|
|
886
|
+
const thisPackageManifest = await readTypedJson(
|
|
887
|
+
import_node_path15.default.join(import_node_path15.default.join(__dirname, "..", "package.json"))
|
|
888
|
+
);
|
|
889
|
+
log.debug("Using isolate-package version", thisPackageManifest.version);
|
|
890
|
+
const targetPackageDir = config.targetPackagePath ? import_node_path15.default.join(process.cwd(), config.targetPackagePath) : process.cwd();
|
|
891
|
+
const workspaceRootDir = config.targetPackagePath ? process.cwd() : import_node_path15.default.join(targetPackageDir, config.workspaceRoot);
|
|
892
|
+
const buildOutputDir = await getBuildOutputDir(targetPackageDir);
|
|
893
|
+
(0, import_node_assert6.default)(
|
|
894
|
+
import_fs_extra14.default.existsSync(buildOutputDir),
|
|
895
|
+
`Failed to find build output path at ${buildOutputDir}. Please make sure you build the source before isolating it.`
|
|
896
|
+
);
|
|
897
|
+
log.debug("Workspace root resolved to", workspaceRootDir);
|
|
898
|
+
log.debug(
|
|
899
|
+
"Isolate target package",
|
|
900
|
+
getRootRelativePath(targetPackageDir, workspaceRootDir)
|
|
901
|
+
);
|
|
902
|
+
const isolateDir = import_node_path15.default.join(targetPackageDir, config.isolateDirName);
|
|
903
|
+
log.debug(
|
|
904
|
+
"Isolate output directory",
|
|
905
|
+
getRootRelativePath(isolateDir, workspaceRootDir)
|
|
906
|
+
);
|
|
907
|
+
if (import_fs_extra14.default.existsSync(isolateDir)) {
|
|
908
|
+
await import_fs_extra14.default.remove(isolateDir);
|
|
909
|
+
log.debug("Cleaned the existing isolate output directory");
|
|
910
|
+
}
|
|
911
|
+
await import_fs_extra14.default.ensureDir(isolateDir);
|
|
912
|
+
const tmpDir = import_node_path15.default.join(isolateDir, "__tmp");
|
|
913
|
+
await import_fs_extra14.default.ensureDir(tmpDir);
|
|
914
|
+
const targetPackageManifest = await readTypedJson(
|
|
915
|
+
import_node_path15.default.join(targetPackageDir, "package.json")
|
|
916
|
+
);
|
|
917
|
+
const packageManager2 = detectPackageManager(workspaceRootDir);
|
|
918
|
+
log.debug(
|
|
919
|
+
"Detected package manager",
|
|
920
|
+
packageManager2.name,
|
|
921
|
+
packageManager2.version
|
|
922
|
+
);
|
|
923
|
+
const packagesRegistry = await createPackagesRegistry(
|
|
924
|
+
workspaceRootDir,
|
|
925
|
+
config.workspacePackages
|
|
926
|
+
);
|
|
927
|
+
const internalPackageNames = listInternalPackages(
|
|
928
|
+
targetPackageManifest,
|
|
929
|
+
packagesRegistry,
|
|
930
|
+
{
|
|
931
|
+
includeDevDependencies: config.includeDevDependencies
|
|
932
|
+
}
|
|
933
|
+
);
|
|
934
|
+
const packedFilesByName = await packDependencies({
|
|
935
|
+
internalPackageNames,
|
|
936
|
+
packagesRegistry,
|
|
937
|
+
packDestinationDir: tmpDir
|
|
938
|
+
});
|
|
939
|
+
await unpackDependencies(
|
|
940
|
+
packedFilesByName,
|
|
941
|
+
packagesRegistry,
|
|
942
|
+
tmpDir,
|
|
943
|
+
isolateDir
|
|
944
|
+
);
|
|
945
|
+
await adaptInternalPackageManifests(
|
|
946
|
+
internalPackageNames,
|
|
947
|
+
packagesRegistry,
|
|
948
|
+
isolateDir
|
|
949
|
+
);
|
|
950
|
+
await processBuildOutputFiles({
|
|
951
|
+
targetPackageDir,
|
|
952
|
+
tmpDir,
|
|
953
|
+
isolateDir
|
|
954
|
+
});
|
|
955
|
+
await adaptTargetPackageManifest(
|
|
956
|
+
targetPackageManifest,
|
|
957
|
+
packagesRegistry,
|
|
958
|
+
isolateDir
|
|
959
|
+
);
|
|
960
|
+
const userDefinedConfig = getUserDefinedConfig();
|
|
961
|
+
if (!isDefined(userDefinedConfig.excludeLockfile)) {
|
|
962
|
+
if (packageManager2.name === "npm" || packageManager2.name === "yarn") {
|
|
963
|
+
config.excludeLockfile = true;
|
|
964
|
+
}
|
|
965
|
+
}
|
|
966
|
+
if (config.excludeLockfile) {
|
|
967
|
+
log.warn("Excluding the lockfile from the isolate output");
|
|
968
|
+
} else {
|
|
969
|
+
await processLockfile({
|
|
970
|
+
workspaceRootDir,
|
|
971
|
+
isolateDir,
|
|
972
|
+
packagesRegistry,
|
|
973
|
+
internalDepPackageNames: internalPackageNames,
|
|
974
|
+
targetPackageDir,
|
|
975
|
+
targetPackageName: targetPackageManifest.name
|
|
976
|
+
});
|
|
977
|
+
}
|
|
978
|
+
if (packageManager2.name === "pnpm") {
|
|
979
|
+
import_fs_extra14.default.copyFileSync(
|
|
980
|
+
import_node_path15.default.join(workspaceRootDir, "pnpm-workspace.yaml"),
|
|
981
|
+
import_node_path15.default.join(isolateDir, "pnpm-workspace.yaml")
|
|
982
|
+
);
|
|
983
|
+
}
|
|
984
|
+
const npmrcPath = import_node_path15.default.join(workspaceRootDir, ".npmrc");
|
|
985
|
+
if (import_fs_extra14.default.existsSync(npmrcPath)) {
|
|
986
|
+
import_fs_extra14.default.copyFileSync(npmrcPath, import_node_path15.default.join(isolateDir, ".npmrc"));
|
|
987
|
+
log.debug("Copied .npmrc file to the isolate output");
|
|
988
|
+
}
|
|
989
|
+
log.debug(
|
|
990
|
+
"Deleting temp directory",
|
|
991
|
+
getRootRelativePath(tmpDir, workspaceRootDir)
|
|
992
|
+
);
|
|
993
|
+
await import_fs_extra14.default.remove(tmpDir);
|
|
994
|
+
log.info("Isolate completed at", isolateDir);
|
|
995
|
+
}
|
|
996
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
997
|
+
0 && (module.exports = {
|
|
998
|
+
isolate
|
|
999
|
+
});
|
|
1000
|
+
//# sourceMappingURL=index.cjs.map
|