isolate-package 1.0.0-beta.9 → 1.0.2
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/README.md +183 -67
- package/dist/index.mjs +33 -29
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -4,11 +4,6 @@ Isolate a monorepo workspace package so that it can be deployed as a completely
|
|
|
4
4
|
self-contained directory with the sources of all its local dependencies
|
|
5
5
|
included.
|
|
6
6
|
|
|
7
|
-
**NOTE**: This package has only been tested with [PNPM](https://pnpm.io/) but it
|
|
8
|
-
was designed to be compatible with NPM and Yarn. That being said, I am
|
|
9
|
-
personally very happy with the switch to PNPM and I encourage anyone to give it
|
|
10
|
-
a try.
|
|
11
|
-
|
|
12
7
|
## Motivation
|
|
13
8
|
|
|
14
9
|
This solution was developed out of a desire to deploy to
|
|
@@ -34,9 +29,78 @@ use-case, I would love to hear about it.
|
|
|
34
29
|
deployment should be deterministic.
|
|
35
30
|
- Optionally choose to include dev dependencies in the isolated output.
|
|
36
31
|
|
|
32
|
+
## Prerequisites
|
|
33
|
+
|
|
34
|
+
Because historically different approaches to monorepos exist, we need to
|
|
35
|
+
establish some basic rules for the isolate process to work.
|
|
36
|
+
|
|
37
|
+
### Define shared package dependencies in the manifest
|
|
38
|
+
|
|
39
|
+
This one might sound obvious, but if the `package.json` from the package you are
|
|
40
|
+
targeting does not list the other monorepo packages it depends on, in either the
|
|
41
|
+
`dependencies` or `devDependencies` list, then the isolate process will not
|
|
42
|
+
include them in the output.
|
|
43
|
+
|
|
44
|
+
How dependencies are listed with regards to versioning is not important, because
|
|
45
|
+
packages are matched based on their name. For example the following flavors all
|
|
46
|
+
work:
|
|
47
|
+
|
|
48
|
+
```cjson
|
|
49
|
+
// package.json
|
|
50
|
+
{
|
|
51
|
+
"dependencies": {
|
|
52
|
+
"shared-package": "workspace:*",
|
|
53
|
+
"shared-package": "*",
|
|
54
|
+
"shared-package": "../shared-package",
|
|
55
|
+
"shared-package": "^1.0.0"
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
So basically, version information is ignored, and if the package name can be
|
|
61
|
+
found in the list of local monorepo packages, it will be processed regardless of
|
|
62
|
+
its version specifier.
|
|
63
|
+
|
|
64
|
+
### Define "files" and "version" in each manifest
|
|
65
|
+
|
|
66
|
+
The isolate process uses (p)npm `pack` to extract files from package
|
|
67
|
+
directories, just like publishing a package would.
|
|
68
|
+
|
|
69
|
+
For this to work it is required that you define the `files` property in each
|
|
70
|
+
`package.json` manifest, as it declares what files should be included in the
|
|
71
|
+
published output.
|
|
72
|
+
|
|
73
|
+
Typically the value contains an array with just the name of the build output
|
|
74
|
+
directory, for example:
|
|
75
|
+
|
|
76
|
+
```cjson
|
|
77
|
+
// package.json
|
|
78
|
+
{
|
|
79
|
+
"files": ["dist"]
|
|
80
|
+
}
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
Also `version` seems to be required by pack. I like setting it to `"0.0.0"` to make it
|
|
84
|
+
clear that the version is not really being used.
|
|
85
|
+
|
|
86
|
+
A few additional files will be included by `pack` automatically, like the
|
|
87
|
+
`package.json` and `README.md` files.
|
|
88
|
+
|
|
89
|
+
### Use a flat structure inside your packages folders
|
|
90
|
+
|
|
91
|
+
At the moment, nesting packages inside packages is not supported.
|
|
92
|
+
|
|
93
|
+
When building the registry of all local packages, `isolate` doesn't drill down
|
|
94
|
+
into the folders. So if you declare your packages to live in `packages/*` it
|
|
95
|
+
will only find the packages directly in that folder and not at
|
|
96
|
+
`packages/nested/more-packages`.
|
|
97
|
+
|
|
98
|
+
You can, however, declare multiple packages folders like `["packages/*",
|
|
99
|
+
"apps/*"]`. It's just that the structure inside them should be flat.
|
|
100
|
+
|
|
37
101
|
## Usage
|
|
38
102
|
|
|
39
|
-
Run `npm install isolate-package --dev` or
|
|
103
|
+
Run `npm install isolate-package --dev` or the equivalent for `yarn` or
|
|
40
104
|
`pnpm`.
|
|
41
105
|
|
|
42
106
|
This package exposes the `isolate` executable. Once installed you can run `npx
|
|
@@ -49,7 +113,8 @@ You will probably want to add the output directory to your `.gitignore` file.
|
|
|
49
113
|
|
|
50
114
|
You can deploy to Firebase from multiple packages in your monorepo, so I advise
|
|
51
115
|
you to co-locate your `firebase.json` file with the source code, and not place
|
|
52
|
-
it in the root of the monorepo.
|
|
116
|
+
it in the root of the monorepo. If you do want to keep the firebase config in
|
|
117
|
+
the root, some additional configuration is required, so read on.
|
|
53
118
|
|
|
54
119
|
In order to deploy to Firebase, the `functions.source` setting in
|
|
55
120
|
`firebase.json` needs to point to the isolated output folder, which would be
|
|
@@ -59,7 +124,7 @@ The `predeploy` phase should first build and then isolate the output.
|
|
|
59
124
|
|
|
60
125
|
Here's an example using [Turborepo](https://turbo.build/):
|
|
61
126
|
|
|
62
|
-
```
|
|
127
|
+
```cjson
|
|
63
128
|
// firebase.json
|
|
64
129
|
{
|
|
65
130
|
"functions": {
|
|
@@ -77,13 +142,69 @@ need to configure a unique `codebase` identifier for each of them. For more
|
|
|
77
142
|
information, [read
|
|
78
143
|
this](https://firebase.google.com/docs/functions/beta/organize-functions).
|
|
79
144
|
|
|
80
|
-
|
|
145
|
+
Make sure your Firebase package adheres to the things mentioned in
|
|
146
|
+
[prerequisites](#prerequisites) and its manifest file contains the field
|
|
147
|
+
`"main"`, or `"module"` if you set `"type": "module"`, so Firebase knows the
|
|
148
|
+
entry point to your source code.
|
|
149
|
+
|
|
150
|
+
### Deploying to Firebase from the root
|
|
151
|
+
|
|
152
|
+
If, for some reason, you choose to keep the `firebase.json` file in the root of
|
|
153
|
+
the monorepo you will have to place a configuration file called
|
|
154
|
+
`isolate.config.json` in the root with the following content:
|
|
81
155
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
156
|
+
```cjson
|
|
157
|
+
// isolate.config.json
|
|
158
|
+
{
|
|
159
|
+
"targetPackagePath": "./packages/your-firebase-package"
|
|
160
|
+
}
|
|
161
|
+
```
|
|
85
162
|
|
|
86
|
-
|
|
163
|
+
The Firebase configuration should then look something like this:
|
|
164
|
+
|
|
165
|
+
```cjson
|
|
166
|
+
// firebase.json
|
|
167
|
+
{
|
|
168
|
+
"functions": {
|
|
169
|
+
"source": "./packages/your-firebase-package/isolate",
|
|
170
|
+
"predeploy": ["turbo build", "isolate"]
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
## Configuration Options
|
|
176
|
+
|
|
177
|
+
For most users no configuration should be required. You can configure the
|
|
178
|
+
isolate process by placing a `isolate.config.json` file in the package that you
|
|
179
|
+
want to isolate, except when you're [deploying to Firebase from the root of the
|
|
180
|
+
workspace](#deploying-firebase-from-the-root).
|
|
181
|
+
|
|
182
|
+
For the config file to be picked up, you will have to execute `isolate` from the
|
|
183
|
+
same location, as it uses the current working directory.
|
|
184
|
+
|
|
185
|
+
Below you will find a description of every available option.
|
|
186
|
+
|
|
187
|
+
### buildDirName
|
|
188
|
+
|
|
189
|
+
Type: `string | undefined`, default: `undefined`
|
|
190
|
+
|
|
191
|
+
The name of the build output directory name. When undefined it is automatically
|
|
192
|
+
detected via `tsconfig.json`. When you are not using Typescript you can use this
|
|
193
|
+
setting to specify where the build output files are located.
|
|
194
|
+
|
|
195
|
+
### includeDevDependencies
|
|
196
|
+
|
|
197
|
+
Type: `boolean`, default: `false`
|
|
198
|
+
|
|
199
|
+
By default devDependencies are ignored and stripped from the isolated output
|
|
200
|
+
`package.json` files. If you enable this the devDependencies will be included
|
|
201
|
+
and isolated just like the production dependencies.
|
|
202
|
+
|
|
203
|
+
### isolateDirName
|
|
204
|
+
|
|
205
|
+
Type: `string`, default: `"isolate"`
|
|
206
|
+
|
|
207
|
+
The name of the isolate output directory.
|
|
87
208
|
|
|
88
209
|
### logLevel
|
|
89
210
|
|
|
@@ -93,6 +214,38 @@ Because the configuration loader depends on this setting, its output is not
|
|
|
93
214
|
affected by this setting. If you want to debug the configuration set
|
|
94
215
|
`ISOLATE_CONFIG_LOG_LEVEL=debug` before you run `isolate`
|
|
95
216
|
|
|
217
|
+
### targetPackagePath
|
|
218
|
+
|
|
219
|
+
Type: `string`, default: `undefined`
|
|
220
|
+
|
|
221
|
+
Only when you decide to place the isolate configuration in the root of the
|
|
222
|
+
monorepo, you use this setting to point it to the target you want to isolate,
|
|
223
|
+
e.g. `./packages/my-firebase-package`.
|
|
224
|
+
|
|
225
|
+
If this option is used the `workspaceRoot` setting will be ignored and assumed
|
|
226
|
+
to be the current working directory.
|
|
227
|
+
|
|
228
|
+
### tsconfigPath
|
|
229
|
+
|
|
230
|
+
Type: `string`, default: `"./tsconfig.json"`
|
|
231
|
+
|
|
232
|
+
The path to the `tsconfig.json` file relative to the package you want to
|
|
233
|
+
isolate. The tsconfig is only used for reading the `compilerOptions.outDir`
|
|
234
|
+
setting. If no tsconfig is found, possibly because you are not using Typescript
|
|
235
|
+
in your project, the process will fall back to the `buildDirName` setting.
|
|
236
|
+
|
|
237
|
+
### workspacePackages
|
|
238
|
+
|
|
239
|
+
Type: `string[] | undefined`, default: `undefined`
|
|
240
|
+
|
|
241
|
+
When workspacePackages is not defined, `isolate` will try to find the packages
|
|
242
|
+
in the workspace by looking up the settings in `pnpm-workspace.yaml` or
|
|
243
|
+
`package.json` files depending on the detected package manager.
|
|
244
|
+
|
|
245
|
+
In case this fails, you can override this process by specifying globs manually.
|
|
246
|
+
For example `"workspacePackages": ["packages/*", "apps/*"]`. Paths are relative
|
|
247
|
+
from the root of the workspace.
|
|
248
|
+
|
|
96
249
|
### workspaceRoot
|
|
97
250
|
|
|
98
251
|
Type: `string`, default: `"../.."`
|
|
@@ -118,70 +271,33 @@ packages
|
|
|
118
271
|
└─ package.json
|
|
119
272
|
```
|
|
120
273
|
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
Type: `string[] | undefined`, default: `undefined`
|
|
124
|
-
|
|
125
|
-
When workspacePackages is not defined, `isolate` will try to find the packages
|
|
126
|
-
in the workspace by looking up the settings in `pnpm-workspace.yaml` or
|
|
127
|
-
`package.json` files depending on the detected package manager.
|
|
128
|
-
|
|
129
|
-
In case this fails, you can override this process by specifying globs manually.
|
|
130
|
-
For example `"workspacePackages": ["packages/*", "apps/*"]`. Paths are relative
|
|
131
|
-
from the root of the workspace.
|
|
132
|
-
|
|
133
|
-
### isolateOutDir
|
|
134
|
-
|
|
135
|
-
Type: `string`, default: `"isolate"`
|
|
136
|
-
|
|
137
|
-
The name of the isolate output directory.
|
|
138
|
-
|
|
139
|
-
### includeDevDependencies
|
|
140
|
-
|
|
141
|
-
Type: `boolean`, default: `false`
|
|
142
|
-
|
|
143
|
-
By default devDependencies are ignored and stripped from the isolated output
|
|
144
|
-
`package.json` files. If you enable this the devDependencies will be included
|
|
145
|
-
and isolated just like the production dependencies.
|
|
146
|
-
|
|
147
|
-
### tsconfigPath
|
|
148
|
-
|
|
149
|
-
Type: `string`, default: `"./tsconfig.json"`
|
|
150
|
-
|
|
151
|
-
The path to the `tsconfig.json` file relative to the package you want to
|
|
152
|
-
isolate. The tsconfig is only used for reading the `compilerOptions.outDir`
|
|
153
|
-
setting. If no tsconfig is found, possibly because you are not using Typescript
|
|
154
|
-
in your project, the process will fall back to the `buildOutputDir` setting.
|
|
155
|
-
|
|
156
|
-
### buildOutputDir
|
|
157
|
-
|
|
158
|
-
Type: `string | undefined`, default: `undefined`
|
|
159
|
-
|
|
160
|
-
When you are not using Typescript you can use this setting to specify where the
|
|
161
|
-
build output files are located.
|
|
274
|
+
When you use the `targetPackagePath` option, this setting will be ignored.
|
|
162
275
|
|
|
163
276
|
## Troubleshooting
|
|
164
277
|
|
|
165
|
-
If something is not working
|
|
166
|
-
|
|
167
|
-
|
|
278
|
+
If something is not working, I advise you to add a `isolate.config.json` file,
|
|
279
|
+
and set `"logLevel"` to `"debug"`. This should give you detailed feedback in the
|
|
280
|
+
console.
|
|
281
|
+
|
|
282
|
+
In addition define an environment variable to debug the configuration being used
|
|
283
|
+
by setting `ISOLATE_CONFIG_LOG_LEVEL=debug` before you execute `isolate`
|
|
168
284
|
|
|
169
|
-
|
|
170
|
-
|
|
285
|
+
When debugging Firebase deployment issues it might be convenient to trigger the
|
|
286
|
+
isolate process manually with `npx isolate` and possibly
|
|
171
287
|
`ISOLATE_CONFIG_LOG_LEVEL=debug npx isolate`
|
|
172
288
|
|
|
173
289
|
## Lockfiles
|
|
174
290
|
|
|
175
|
-
I inspected the NPM
|
|
291
|
+
I inspected the NPM lockfile as well as the Yarn v1 and v3 lockfiles and they
|
|
176
292
|
seem to have a flat structure unrelated to the workspace packages structure, so
|
|
177
|
-
I made the assumption that they can be copied as-is.
|
|
293
|
+
I have made the assumption that they can be copied to the isolate output as-is.
|
|
178
294
|
|
|
179
295
|
The PNPM lockfile clearly has a structure describing the different packages by
|
|
180
296
|
their relative paths, and so to correct the lockfile it is adapted before being
|
|
181
|
-
|
|
297
|
+
stored to the isolate directory.
|
|
182
298
|
|
|
183
299
|
I am not sure the Firebase deploy pipeline is actually detecting a
|
|
184
|
-
pnpm-lock.yaml file and using PNPM to install packages. This needs to be
|
|
300
|
+
`pnpm-lock.yaml` file and using PNPM to install its packages. This needs to be
|
|
185
301
|
verified...
|
|
186
302
|
|
|
187
303
|
## Used Terminology
|
|
@@ -191,8 +307,8 @@ definition for the term "workspace". If you want to read the code it might be
|
|
|
191
307
|
good to know that I consider the workspace to be the monorepo itself, in other
|
|
192
308
|
words, the overall structure that holds all the packages.
|
|
193
309
|
|
|
194
|
-
Also, in the code you see the word manifest a lot
|
|
195
|
-
a package.json file.
|
|
310
|
+
Also, in the code you see the word manifest a lot, and it simply means to the
|
|
311
|
+
contents of a `package.json` file.
|
|
196
312
|
|
|
197
313
|
## Binary as ESM module
|
|
198
314
|
|
|
@@ -201,5 +317,5 @@ extension, otherwise a non-ESM workspace will try to execute it as commonJS. For
|
|
|
201
317
|
details on this read [this article from Alex
|
|
202
318
|
Rauschmayer](https://exploringjs.com/nodejs-shell-scripting/ch_creating-shell-scripts.html#node.js-esm-modules-as-standalone-shell-scripts-on-unix)
|
|
203
319
|
|
|
204
|
-
|
|
205
|
-
|
|
320
|
+
For PNPM the hashbang at the top of the script was not required, but Yarn 3 did
|
|
321
|
+
not seem to execute without it.
|
package/dist/index.mjs
CHANGED
|
@@ -37,7 +37,8 @@ function filterObjectUndefined(object) {
|
|
|
37
37
|
|
|
38
38
|
// src/utils/get-relative-path.ts
|
|
39
39
|
function getRelativePath(path14, relativeTo) {
|
|
40
|
-
|
|
40
|
+
const strippedPath = path14.replace(relativeTo, "");
|
|
41
|
+
return strippedPath.startsWith("/") ? `.${strippedPath}` : `./${strippedPath}`;
|
|
41
42
|
}
|
|
42
43
|
|
|
43
44
|
// src/utils/inspect-value.ts
|
|
@@ -182,13 +183,14 @@ import fs6 from "fs-extra";
|
|
|
182
183
|
import { isEmpty } from "lodash-es";
|
|
183
184
|
import path4 from "node:path";
|
|
184
185
|
var configDefaults = {
|
|
185
|
-
|
|
186
|
-
workspaceRoot: "../..",
|
|
187
|
-
isolateOutDir: "./isolate",
|
|
186
|
+
buildDirName: void 0,
|
|
188
187
|
includeDevDependencies: false,
|
|
188
|
+
isolateDirName: "isolate",
|
|
189
|
+
logLevel: "info",
|
|
190
|
+
targetPackagePath: void 0,
|
|
189
191
|
tsconfigPath: "./tsconfig.json",
|
|
190
192
|
workspacePackages: void 0,
|
|
191
|
-
|
|
193
|
+
workspaceRoot: "../.."
|
|
192
194
|
};
|
|
193
195
|
var __config;
|
|
194
196
|
var validConfigKeys = Object.keys(configDefaults);
|
|
@@ -292,11 +294,11 @@ async function createPackagesRegistry(workspaceRootDir, workspacePackagesOverrid
|
|
|
292
294
|
const manifestPath = path7.join(rootRelativeDir, "package.json");
|
|
293
295
|
if (!fs8.existsSync(manifestPath)) {
|
|
294
296
|
log2.warn(
|
|
295
|
-
`Ignoring directory
|
|
297
|
+
`Ignoring directory ./${rootRelativeDir} because it does not contain a package.json file`
|
|
296
298
|
);
|
|
297
299
|
return;
|
|
298
300
|
} else {
|
|
299
|
-
log2.debug(`Registering package
|
|
301
|
+
log2.debug(`Registering package ./${rootRelativeDir}`);
|
|
300
302
|
const manifest = await readTypedJson(
|
|
301
303
|
path7.join(rootRelativeDir, "package.json")
|
|
302
304
|
);
|
|
@@ -315,28 +317,34 @@ async function createPackagesRegistry(workspaceRootDir, workspacePackagesOverrid
|
|
|
315
317
|
return registry;
|
|
316
318
|
}
|
|
317
319
|
|
|
318
|
-
// src/helpers/
|
|
320
|
+
// src/helpers/get-build-output-dir.ts
|
|
319
321
|
import fs9 from "fs-extra";
|
|
320
322
|
import path8 from "node:path";
|
|
321
|
-
import
|
|
322
|
-
async function
|
|
323
|
+
import outdent from "outdent";
|
|
324
|
+
async function getBuildOutputDir(targetPackageDir) {
|
|
323
325
|
const config2 = getConfig();
|
|
324
326
|
const log2 = createLogger(getConfig().logLevel);
|
|
325
|
-
if (config2.
|
|
326
|
-
log2.debug("Using
|
|
327
|
-
return path8.join(targetPackageDir, config2.
|
|
327
|
+
if (config2.buildDirName) {
|
|
328
|
+
log2.debug("Using buildDirName from config:", config2.buildDirName);
|
|
329
|
+
return path8.join(targetPackageDir, config2.buildDirName);
|
|
328
330
|
}
|
|
329
331
|
const tsconfigPath = path8.join(targetPackageDir, config2.tsconfigPath);
|
|
332
|
+
log2.debug("Looking for tsconfig at:", tsconfigPath);
|
|
330
333
|
if (fs9.existsSync(tsconfigPath)) {
|
|
331
334
|
const tsconfig = await readTypedJson(tsconfigPath);
|
|
332
335
|
const outDir = tsconfig.compilerOptions?.outDir;
|
|
333
336
|
if (outDir) {
|
|
334
337
|
return path8.join(targetPackageDir, outDir);
|
|
338
|
+
} else {
|
|
339
|
+
throw new Error(outdent`
|
|
340
|
+
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.
|
|
341
|
+
`);
|
|
335
342
|
}
|
|
343
|
+
} else {
|
|
344
|
+
throw new Error(outdent`
|
|
345
|
+
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.
|
|
346
|
+
`);
|
|
336
347
|
}
|
|
337
|
-
log2.error(`Failed to find outDir in tsconfig at ${tsconfigPath}
|
|
338
|
-
Without an isolate.config.json file specifying the buildOutputDir, or outDir provided by tsconfig, we can't know where the build output directory is located. Please configure one of these options.`);
|
|
339
|
-
process2.exit(1);
|
|
340
348
|
}
|
|
341
349
|
|
|
342
350
|
// src/helpers/list-local-dependencies.ts
|
|
@@ -491,8 +499,8 @@ async function unpackDependencies(packedFilesByName, packagesRegistry, tmpDir, i
|
|
|
491
499
|
Object.entries(packedFilesByName).map(async ([packageName, filePath]) => {
|
|
492
500
|
const dir = packagesRegistry[packageName].rootRelativeDir;
|
|
493
501
|
const unpackDir = join(tmpDir, dir);
|
|
502
|
+
log2.debug("Unpacking", path12.basename(filePath));
|
|
494
503
|
await unpack(filePath, unpackDir);
|
|
495
|
-
log2.debug("Unpacked", path12.basename(filePath));
|
|
496
504
|
const destinationDir = join(isolateDir, dir);
|
|
497
505
|
await fs12.ensureDir(destinationDir);
|
|
498
506
|
await fs12.move(join(unpackDir, "package"), destinationDir, {
|
|
@@ -513,29 +521,27 @@ var config = getConfig();
|
|
|
513
521
|
var log = createLogger(config.logLevel);
|
|
514
522
|
sourceMaps.install();
|
|
515
523
|
async function start() {
|
|
516
|
-
const targetPackageDir = process.cwd();
|
|
517
|
-
const
|
|
524
|
+
const targetPackageDir = config.targetPackagePath ? path13.join(process.cwd(), config.targetPackagePath) : process.cwd();
|
|
525
|
+
const workspaceRootDir = config.targetPackagePath ? process.cwd() : path13.join(targetPackageDir, config.workspaceRoot);
|
|
526
|
+
const buildOutputDir = await getBuildOutputDir(targetPackageDir);
|
|
518
527
|
assert3(
|
|
519
528
|
fs13.existsSync(buildOutputDir),
|
|
520
529
|
`Failed to find build output path at ${buildOutputDir}. Please make sure you build the source before isolating it.`
|
|
521
530
|
);
|
|
522
|
-
const workspaceRootDir = path13.join(
|
|
523
|
-
targetPackageDir,
|
|
524
|
-
config.workspaceRoot,
|
|
525
|
-
"/"
|
|
526
|
-
);
|
|
527
531
|
log.debug("Workspace root", workspaceRootDir);
|
|
528
532
|
log.debug(
|
|
529
533
|
"Isolate target package",
|
|
530
534
|
getRelativePath(targetPackageDir, workspaceRootDir)
|
|
531
535
|
);
|
|
532
536
|
const packageManager = detectPackageManager(workspaceRootDir);
|
|
533
|
-
const isolateDir = path13.join(targetPackageDir, config.
|
|
537
|
+
const isolateDir = path13.join(targetPackageDir, config.isolateDirName);
|
|
534
538
|
log.debug(
|
|
535
539
|
"Isolate output dir",
|
|
536
540
|
getRelativePath(isolateDir, workspaceRootDir)
|
|
537
541
|
);
|
|
538
542
|
await fs13.ensureDir(isolateDir);
|
|
543
|
+
await fs13.remove(`${isolateDir}/**/*`);
|
|
544
|
+
log.debug("Cleaned the isolate output directory");
|
|
539
545
|
const packagesRegistry = await createPackagesRegistry(
|
|
540
546
|
workspaceRootDir,
|
|
541
547
|
config.workspacePackages
|
|
@@ -585,10 +591,8 @@ async function start() {
|
|
|
585
591
|
getRelativePath(tmpDir, workspaceRootDir)
|
|
586
592
|
);
|
|
587
593
|
await fs13.remove(tmpDir);
|
|
588
|
-
log.
|
|
589
|
-
|
|
590
|
-
path13.join("./", getRelativePath(isolateDir, targetPackageDir))
|
|
591
|
-
);
|
|
594
|
+
log.debug("Stored isolate output at", isolateDir);
|
|
595
|
+
log.info("Isolate completed");
|
|
592
596
|
}
|
|
593
597
|
start().catch((err) => {
|
|
594
598
|
if (err instanceof Error) {
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/helpers/adapt-manifest-files.ts","../src/helpers/adapt-manifest-workspace-deps.ts","../src/utils/filter-object-undefined.ts","../src/utils/get-relative-path.ts","../src/utils/inspect-value.ts","../src/utils/json.ts","../src/utils/logger.ts","../src/utils/pack.ts","../src/utils/unpack.ts","../src/utils/yaml.ts","../src/helpers/adapt-target-package-manifest.ts","../src/helpers/config.ts","../src/helpers/create-packages-registry.ts","../src/helpers/find-packages-globs.ts","../src/helpers/detect-package-manager.ts","../src/helpers/find-build-output-dir.ts","../src/helpers/list-local-dependencies.ts","../src/helpers/manifest.ts","../src/helpers/pack-dependencies.ts","../src/helpers/patch-workspace-entries.ts","../src/helpers/process-build-output-files.ts","../src/helpers/process-lockfile.ts","../src/helpers/unpack-dependencies.ts"],"sourcesContent":["#!/usr/bin/env node\n\nimport fs from \"fs-extra\";\nimport assert from \"node:assert\";\nimport path from \"node:path\";\nimport sourceMaps from \"source-map-support\";\nimport {\n PackageManifestMinimum,\n adaptManifestFiles,\n adaptTargetPackageManifest,\n createPackagesRegistry,\n detectPackageManager,\n findBuildOutputDir,\n getConfig,\n listLocalDependencies,\n packDependencies,\n processBuildOutputFiles,\n processLockfile,\n unpackDependencies,\n} from \"~/helpers\";\nimport { createLogger, getRelativePath, readTypedJson } from \"~/utils\";\n\nconst config = getConfig();\nconst log = createLogger(config.logLevel);\n\nsourceMaps.install();\n\nasync function start() {\n const targetPackageDir = process.cwd();\n\n const buildOutputDir = await findBuildOutputDir(targetPackageDir);\n\n assert(\n fs.existsSync(buildOutputDir),\n `Failed to find build output path at ${buildOutputDir}. Please make sure you build the source before isolating it.`\n );\n\n /**\n * We want a trailing slash here. Functionally it doesn't matter, but it makes\n * the relative paths print correctly in the cli output.\n */\n const workspaceRootDir = path.join(\n targetPackageDir,\n config.workspaceRoot,\n \"/\"\n );\n\n log.debug(\"Workspace root\", workspaceRootDir);\n log.debug(\n \"Isolate target package\",\n getRelativePath(targetPackageDir, workspaceRootDir)\n );\n\n const packageManager = detectPackageManager(workspaceRootDir);\n\n const isolateDir = path.join(targetPackageDir, config.isolateOutDir);\n\n log.debug(\n \"Isolate output dir\",\n getRelativePath(isolateDir, workspaceRootDir)\n );\n\n /**\n * Make sure the isolate dir exists so we can write to it\n */\n await fs.ensureDir(isolateDir);\n\n /**\n * Build a packages registry so we can find the workspace packages by name and\n * have access to their manifest files and relative paths.\n */\n const packagesRegistry = await createPackagesRegistry(\n workspaceRootDir,\n config.workspacePackages\n );\n\n const tmpDir = path.join(isolateDir, \"__tmp\");\n await fs.ensureDir(tmpDir);\n\n /**\n * PNPM pack seems to be much faster than NPM pack so we use that when PNPM is\n * detected. We log it here because the pack function will be called\n * recursively.\n */\n if (packageManager === \"pnpm\") {\n log.debug(\"Using pnpm to pack dependencies\");\n } else {\n log.debug(\"Using npm to pack dependencies\");\n }\n\n const manifest = await readTypedJson<PackageManifestMinimum>(\n path.join(targetPackageDir, \"package.json\")\n );\n\n const localDependencies = listLocalDependencies(manifest, packagesRegistry, {\n includeDevDependencies: config.includeDevDependencies,\n });\n\n const packedFilesByName = await packDependencies({\n localDependencies,\n packagesRegistry,\n packDestinationDir: tmpDir,\n packageManager,\n });\n\n await unpackDependencies(\n packedFilesByName,\n packagesRegistry,\n tmpDir,\n isolateDir\n );\n\n /**\n * Adapt the manifest files for all the unpacked local dependencies\n */\n await adaptManifestFiles(localDependencies, packagesRegistry, isolateDir);\n\n /**\n * Pack the target package directory, and unpack it in the isolate location\n */\n await processBuildOutputFiles({\n targetPackageDir,\n tmpDir,\n packageManager,\n isolateDir,\n });\n\n /**\n * Copy the target manifest file to the isolate location and adapt its\n * workspace dependencies to point to the isolated packages.\n */\n await adaptTargetPackageManifest(manifest, packagesRegistry, isolateDir);\n\n /**\n * Copy and adapt the lockfile\n */\n await processLockfile({\n workspaceRootDir,\n targetPackageName: manifest.name,\n isolateDir,\n packagesRegistry,\n packageManager,\n });\n\n /**\n * Clean up\n */\n log.debug(\n \"Deleting temporary directory\",\n getRelativePath(tmpDir, workspaceRootDir)\n );\n await fs.remove(tmpDir);\n\n log.info(\n \"Isolate completed at\",\n path.join(\"./\", getRelativePath(isolateDir, targetPackageDir))\n );\n}\n\nstart().catch((err) => {\n if (err instanceof Error) {\n log.error(err.stack);\n process.exit(1);\n } else {\n console.error(err);\n }\n});\n\nprocess.on(\"unhandledRejection\", log.error);\n","import fs from \"fs-extra\";\nimport path from \"node:path\";\nimport {\n PackagesRegistry,\n adaptManifestWorkspaceDeps,\n getConfig,\n} from \"~/helpers\";\n\nexport async function adaptManifestFiles(\n localDependencies: string[],\n packagesRegistry: PackagesRegistry,\n isolateDir: string,\n) {\n await Promise.all(\n localDependencies.map(async (packageName) => {\n const { manifest, rootRelativeDir } = packagesRegistry[packageName];\n\n const outputManifest = adaptManifestWorkspaceDeps(\n { manifest, packagesRegistry },\n { includeDevDependencies: getConfig().includeDevDependencies },\n );\n\n await fs.writeFile(\n path.join(isolateDir, rootRelativeDir, \"package.json\"),\n JSON.stringify(outputManifest, null, 2),\n );\n }),\n );\n}\n","import { omit } from \"lodash-es\";\nimport { filterObjectUndefined } from \"~/utils\";\nimport {\n PackageManifestMinimum,\n PackagesRegistry,\n patchWorkspaceEntries,\n} from \".\";\n\nexport function adaptManifestWorkspaceDeps(\n {\n manifest,\n packagesRegistry,\n }: {\n manifest: PackageManifestMinimum;\n packagesRegistry: PackagesRegistry;\n },\n opts: { includeDevDependencies?: boolean } = {},\n): PackageManifestMinimum {\n return Object.assign(\n omit(manifest, [\"scripts\", \"devDependencies\"]),\n filterObjectUndefined({\n dependencies: manifest.dependencies\n ? patchWorkspaceEntries(manifest.dependencies, packagesRegistry)\n : undefined,\n devDependencies:\n opts.includeDevDependencies && manifest.devDependencies\n ? patchWorkspaceEntries(manifest.devDependencies, packagesRegistry)\n : undefined,\n }),\n );\n}\n","export function filterObjectUndefined(object: Record<string, unknown>) {\n return Object.fromEntries(\n Object.entries(object).filter(([_, value]) => value !== undefined),\n );\n}\n","export function getRelativePath(path: string, relativeTo: string) {\n return path.replace(relativeTo, \"\");\n}\n","import { inspect } from \"node:util\";\nimport { JsonValue } from \"type-fest\";\n\nexport function inspectValue(value: JsonValue) {\n return inspect(value, false, 4, true);\n}\n","import fs from \"fs-extra\";\n\n/**\n * @TODO pass in zod schema and validate\n */\nexport function readTypedJsonSync<T>(filePath: string) {\n const rawContent = fs.readFileSync(filePath, \"utf-8\");\n const data = JSON.parse(rawContent) as T;\n return data;\n}\n\nexport async function readTypedJson<T>(filePath: string) {\n const rawContent = await fs.readFile(filePath, \"utf-8\");\n const data = JSON.parse(rawContent) as T;\n return data;\n}\n","import chalk from \"chalk\";\nimport { IsolateConfigResolved } from \"~/helpers\";\n\nexport type Logger = {\n debug(...args: any[]): void;\n info(...args: any[]): void;\n warn(...args: any[]): void;\n error(...args: any[]): void;\n};\n\nexport function createLogger(\n logLevel: IsolateConfigResolved[\"logLevel\"]\n): Logger {\n return {\n debug(...args: any[]) {\n if (logLevel === \"debug\") {\n console.log(chalk.blue(\"debug\"), ...args);\n }\n },\n info(...args: any[]) {\n if (logLevel === \"debug\" || logLevel === \"info\") {\n console.log(chalk.green(\"info\"), ...args);\n }\n },\n warn(...args: any[]) {\n if (logLevel === \"debug\" || logLevel === \"info\" || logLevel === \"warn\") {\n console.log(chalk.yellow(\"warning\"), ...args);\n }\n },\n error(...args: any[]) {\n console.log(chalk.red(\"error\"), ...args);\n },\n };\n}\n","import { exec } from \"node:child_process\";\nimport path from \"node:path\";\nimport { PackageManager, getConfig } from \"~/helpers\";\nimport { createLogger } from \"./logger\";\n\nexport async function pack(\n srcDir: string,\n destDir: string,\n packageManager: PackageManager,\n) {\n const log = createLogger(getConfig().logLevel);\n const cwd = process.cwd();\n process.chdir(srcDir);\n\n /**\n * PNPM pack seems to be a lot faster than NPM pack, so when PNPM is detected we\n * use that instead.\n */\n switch (packageManager) {\n case \"pnpm\": {\n const stdout = await new Promise<string>((resolve, reject) => {\n exec(`pnpm pack --pack-destination ${destDir}`, (err, stdout) => {\n if (err) {\n return reject(err);\n }\n\n resolve(stdout);\n });\n });\n\n /**\n * Trim newlines and whitespace\n */\n const packedFilePath = stdout.trim();\n\n log.debug(\"Packed\", path.basename(packedFilePath));\n\n process.chdir(cwd);\n return packedFilePath;\n }\n\n case \"yarn\":\n case \"npm\": {\n const stdout = await new Promise<string>((resolve, reject) => {\n exec(`npm pack --pack-destination ${destDir}`, (err, stdout) => {\n if (err) {\n return reject(err);\n }\n\n resolve(stdout);\n });\n });\n\n /**\n * Trim newlines and whitespace\n */\n const packedFileName = stdout.trim();\n\n log.debug(\"Packed\", packedFileName);\n\n process.chdir(cwd);\n return path.join(destDir, packedFileName);\n }\n }\n}\n","import fs from \"fs-extra\";\nimport tar from \"tar-fs\";\nimport { createGunzip } from \"zlib\";\n\nexport async function unpack(filePath: string, unpackDir: string) {\n await new Promise<void>((resolve, reject) => {\n fs.createReadStream(filePath)\n .pipe(createGunzip())\n .pipe(tar.extract(unpackDir))\n .on(\"finish\", () => resolve())\n .on(\"error\", (err) => reject(err));\n });\n}\n","import fs from \"fs-extra\";\nimport yaml from \"yaml\";\n\nexport function readTypedYamlSync<T>(filePath: string) {\n const rawContent = fs.readFileSync(filePath, \"utf-8\");\n const data = yaml.parse(rawContent);\n /**\n * @TODO add some zod validation maybe\n */\n return data as T;\n}\n\nexport function writeTypedYamlSync<T>(filePath: string, content: T) {\n /**\n * @TODO add some zod validation maybe\n */\n fs.writeFileSync(filePath, yaml.stringify(content), \"utf-8\");\n}\n","import fs from \"fs-extra\";\nimport path from \"node:path\";\nimport {\n PackageManifestMinimum,\n PackagesRegistry,\n adaptManifestWorkspaceDeps,\n getConfig,\n} from \"~/helpers\";\n\nexport async function adaptTargetPackageManifest(\n manifest: PackageManifestMinimum,\n packagesRegistry: PackagesRegistry,\n isolateDir: string,\n) {\n const outputManifest = adaptManifestWorkspaceDeps(\n {\n manifest,\n packagesRegistry,\n },\n { includeDevDependencies: getConfig().includeDevDependencies },\n );\n\n await fs.writeFile(\n path.join(isolateDir, \"package.json\"),\n JSON.stringify(outputManifest, null, 2),\n );\n}\n","import fs from \"fs-extra\";\nimport { isEmpty } from \"lodash-es\";\nimport path from \"node:path\";\nimport { createLogger, inspectValue, readTypedJsonSync } from \"~/utils\";\n\nexport type IsolateConfigResolved = {\n logLevel: \"info\" | \"debug\" | \"warn\" | \"error\";\n workspaceRoot: string;\n workspacePackages?: string[];\n isolateOutDir: string;\n includeDevDependencies: boolean;\n tsconfigPath: string;\n buildOutputDir?: string;\n};\n\nexport type IsolateConfig = Partial<IsolateConfigResolved>;\n\nconst configDefaults: IsolateConfigResolved = {\n logLevel: \"info\",\n workspaceRoot: \"../..\",\n isolateOutDir: \"./isolate\",\n includeDevDependencies: false,\n tsconfigPath: \"./tsconfig.json\",\n workspacePackages: undefined,\n buildOutputDir: undefined,\n};\n\n/**\n * Only initialize the configuration once, and keeping it here for subsequent\n * calls to getConfig.\n */\nlet __config: IsolateConfigResolved | undefined;\n\nconst validConfigKeys = Object.keys(configDefaults);\n\nconst CONFIG_FILE_NAME = \"isolate.config.json\";\n\ntype LogLevel = IsolateConfigResolved[\"logLevel\"];\n\nexport function getConfig(): IsolateConfigResolved {\n if (__config) {\n return __config;\n }\n\n /**\n * Since the logLevel is set via config we can't use it to determine if we\n * should output verbose logging as part of the config loading process. Using\n * the env var ISOLATE_CONFIG_LOG_LEVEL you have the option to log debug\n * output.\n */\n const log = createLogger(\n (process.env.ISOLATE_CONFIG_LOG_LEVEL as LogLevel) ?? \"warn\"\n );\n\n const configFilePath = path.join(process.cwd(), CONFIG_FILE_NAME);\n\n log.debug(`Attempting to load config from ${configFilePath}`);\n\n const configFromFile = fs.existsSync(configFilePath)\n ? readTypedJsonSync<IsolateConfig>(configFilePath)\n : {};\n\n const foreignKeys = Object.keys(configFromFile).filter(\n (key) => !validConfigKeys.includes(key)\n );\n\n if (!isEmpty(foreignKeys)) {\n log.warn(`Found invalid config settings:`, foreignKeys.join(\", \"));\n }\n\n const config = Object.assign(\n {},\n configDefaults,\n configFromFile\n ) satisfies IsolateConfigResolved;\n\n log.debug(\"Using configuration:\", inspectValue(config));\n\n __config = config;\n return config;\n}\n","import fs from \"fs-extra\";\nimport { globSync } from \"glob\";\nimport { set } from \"lodash-es\";\nimport path from \"node:path\";\nimport { createLogger, readTypedJson } from \"~/utils\";\nimport { getConfig } from \"./config\";\nimport { findPackagesGlobs } from \"./find-packages-globs\";\n\nexport type PackageManifestMinimum = {\n name: string;\n dependencies?: Record<string, string>;\n devDependencies?: Record<string, string>;\n main: string;\n module?: string;\n exports?: Record<string, { require: string; import: string }>;\n files: string[];\n version?: string;\n typings?: string;\n scripts?: Record<string, string>;\n};\n\nexport type WorkspacePackageInfo = {\n absoluteDir: string;\n /**\n * The path of the package relative to the workspace root. This is the path\n * referenced in the lock file.\n */\n rootRelativeDir: string;\n /**\n * The package.json file contents\n */\n manifest: PackageManifestMinimum;\n};\n\nexport type PackagesRegistry = Record<string, WorkspacePackageInfo>;\n\n/**\n * Build a list of all packages in the workspace, depending on the package\n * manager used, with a possible override from the config file. The list contains\n * the manifest with some directory info mapped by module name.\n */\nexport async function createPackagesRegistry(\n workspaceRootDir: string,\n workspacePackagesOverride: string[] | undefined\n): Promise<PackagesRegistry> {\n const log = createLogger(getConfig().logLevel);\n\n if (workspacePackagesOverride) {\n log.debug(\n `Override workspace packages via config: ${workspacePackagesOverride}`\n );\n }\n\n const packagesGlobs =\n workspacePackagesOverride ?? findPackagesGlobs(workspaceRootDir);\n\n const cwd = process.cwd();\n process.chdir(workspaceRootDir);\n\n const allPackages = packagesGlobs\n .flatMap((glob) => globSync(glob))\n /**\n * Make sure to filter any loose files that might hang around.\n */\n .filter((dir) => fs.lstatSync(dir).isDirectory());\n\n const registry: PackagesRegistry = (\n await Promise.all(\n allPackages.map(async (rootRelativeDir) => {\n const manifestPath = path.join(rootRelativeDir, \"package.json\");\n\n if (!fs.existsSync(manifestPath)) {\n log.warn(\n `Ignoring directory ${rootRelativeDir} because it does not contain a package.json file`\n );\n return;\n } else {\n log.debug(`Registering package ${rootRelativeDir}`);\n\n const manifest = await readTypedJson<PackageManifestMinimum>(\n path.join(rootRelativeDir, \"package.json\")\n );\n\n return {\n manifest,\n rootRelativeDir,\n absoluteDir: path.join(workspaceRootDir, rootRelativeDir),\n };\n }\n })\n )\n ).reduce<PackagesRegistry>(\n (acc, info) => (info ? set(acc, info.manifest.name, info) : acc),\n {}\n );\n\n process.chdir(cwd);\n\n return registry;\n}\n","import path from \"node:path\";\nimport {\n createLogger,\n inspectValue,\n readTypedJsonSync,\n readTypedYamlSync,\n} from \"~/utils\";\nimport { getConfig } from \"./config\";\nimport { detectPackageManager } from \"./detect-package-manager\";\n\n/**\n * Find the globs that define where the packages are located within the\n * monorepo. This configuration is dependent on the package manager used, and I\n * don't know if we're covering all cases yet...\n */\nexport function findPackagesGlobs(workspaceRootDir: string) {\n const log = createLogger(getConfig().logLevel);\n\n const packageManager = detectPackageManager(workspaceRootDir);\n\n switch (packageManager) {\n case \"pnpm\": {\n const { packages: globs } = readTypedYamlSync<{ packages: string[] }>(\n path.join(workspaceRootDir, \"pnpm-workspace.yaml\"),\n );\n\n log.debug(\"Detected pnpm packages globs:\", inspectValue(globs));\n return globs;\n }\n case \"yarn\":\n case \"npm\": {\n const workspaceRootManifestPath = path.join(\n workspaceRootDir,\n \"package.json\",\n );\n\n const { workspaces } = readTypedJsonSync<{ workspaces: string[] }>(\n workspaceRootManifestPath,\n );\n\n if (!workspaces) {\n throw new Error(\n `No workspaces field found in ${workspaceRootManifestPath}`,\n );\n }\n\n return workspaces;\n }\n }\n}\n","import fs from \"fs-extra\";\nimport path from \"node:path\";\n\nexport type PackageManager = \"pnpm\" | \"yarn\" | \"npm\";\n\nexport function detectPackageManager(workspaceRoot: string): PackageManager {\n if (fs.existsSync(path.join(workspaceRoot, \"pnpm-lock.yaml\"))) {\n return \"pnpm\";\n }\n\n if (fs.existsSync(path.join(workspaceRoot, \"yarn.lock\"))) {\n return \"yarn\";\n }\n\n if (fs.existsSync(path.join(workspaceRoot, \"package-lock.json\"))) {\n return \"npm\";\n }\n\n throw new Error(`Failed to detect package manager`);\n}\n","import fs from \"fs-extra\";\nimport path from \"node:path\";\nimport process from \"node:process\";\nimport { an } from \"vitest/dist/types-e3c9754d\";\nimport { getConfig } from \"~/helpers\";\nimport { createLogger, readTypedJson } from \"~/utils\";\n\n/**\n * Find the build output dir by reading the tsconfig.json file or if that\n * doesn't exist by looking for a dist, build, or output directory.\n */\nexport async function findBuildOutputDir(targetPackageDir: string) {\n const config = getConfig();\n const log = createLogger(getConfig().logLevel);\n\n if (config.buildOutputDir) {\n log.debug(\"Using buildOutputDir from config:\", config.buildOutputDir);\n return path.join(targetPackageDir, config.buildOutputDir);\n }\n\n const tsconfigPath = path.join(targetPackageDir, config.tsconfigPath);\n\n if (fs.existsSync(tsconfigPath)) {\n const tsconfig = await readTypedJson<{\n compilerOptions?: { outDir?: string };\n }>(tsconfigPath);\n\n const outDir = tsconfig.compilerOptions?.outDir;\n\n if (outDir) {\n return path.join(targetPackageDir, outDir);\n }\n }\n\n log.error(`Failed to find outDir in tsconfig at ${tsconfigPath}\nWithout an isolate.config.json file specifying the buildOutputDir, or outDir provided by tsconfig, we can't know where the build output directory is located. Please configure one of these options.`);\n\n process.exit(1);\n\n // throw new Error(`Failed to find outDir in tsconfig at ${tsconfigPath}\n // Without an isolate.config.json file specifying the buildOutputDir, or outDir provided by tsconfig, we can't know where the build output directory is located. Please configure one of these options.`);\n}\n","import {\n PackageManifestMinimum,\n PackagesRegistry,\n} from \"./create-packages-registry\";\n\n/**\n * Recursively list the packages from dependencies (and optionally\n * devDependencies) that are found in the workspace.\n *\n * Here we do not need to rely on packages being declared as \"workspace:\" in the\n * manifest. We can simply compare the package names with the list of packages\n * that were found via the workspace glob patterns and added to the registry.\n */\nexport function listLocalDependencies(\n manifest: PackageManifestMinimum,\n packagesRegistry: PackagesRegistry,\n { includeDevDependencies = false } = {},\n): string[] {\n const allWorkspacePackageNames = Object.keys(packagesRegistry);\n\n const localDependencyPackageNames = (\n includeDevDependencies\n ? [\n ...Object.keys(manifest.dependencies ?? {}),\n ...Object.keys(manifest.devDependencies ?? {}),\n ]\n : Object.keys(manifest.dependencies ?? {})\n ).filter((name) => allWorkspacePackageNames.includes(name));\n\n const nestedLocalDependencies = localDependencyPackageNames.flatMap(\n (packageName) =>\n listLocalDependencies(\n packagesRegistry[packageName].manifest,\n packagesRegistry,\n { includeDevDependencies },\n ),\n );\n\n return localDependencyPackageNames.concat(nestedLocalDependencies);\n}\n","import path from \"node:path\";\nimport { readTypedJson } from \"~/utils\";\nimport { PackageManifestMinimum } from \"./create-packages-registry\";\n\nexport async function importManifest(packageDir: string) {\n return readTypedJson<PackageManifestMinimum>(\n path.join(packageDir, \"package.json\"),\n );\n}\n","import assert from \"node:assert\";\nimport { createLogger, pack } from \"~/utils\";\nimport { getConfig } from \"./config\";\nimport { PackagesRegistry } from \"./create-packages-registry\";\nimport { PackageManager } from \"./detect-package-manager\";\n\n/**\n * Pack dependencies so that we extract only the files that are supposed to be\n * published by the packages.\n *\n * @returns A map of package names to the path of the packed file\n */\nexport async function packDependencies({\n /**\n * All packages found in the monorepo by workspaces declaration\n */\n packagesRegistry,\n /**\n * The package names that appear to be local dependencies\n */\n localDependencies,\n /**\n * The directory where the isolated package and all its dependencies will end\n * up. This is also the directory from where the package will be deployed. By\n * default it is a subfolder in targetPackageDir called \"isolate\" but you can\n * configure it.\n */\n packDestinationDir,\n\n packageManager,\n}: {\n packagesRegistry: PackagesRegistry;\n localDependencies: string[];\n packDestinationDir: string;\n packageManager: PackageManager;\n}) {\n const config = getConfig();\n const log = createLogger(config.logLevel);\n\n const packedFileByName: Record<string, string> = {};\n\n for (const dependency of localDependencies) {\n const def = packagesRegistry[dependency];\n\n assert(dependency, `Failed to find package definition for ${dependency}`);\n\n const { name } = def.manifest;\n\n /**\n * If this dependency has already been packed, we skip it. It could happen\n * because we are packing workspace dependencies recursively.\n */\n if (packedFileByName[name]) {\n log.debug(`Skipping ${name} because it has already been packed`);\n continue;\n }\n\n packedFileByName[name] = await pack(\n def.absoluteDir,\n packDestinationDir,\n packageManager,\n );\n\n /**\n * @TODO call recursively\n */\n }\n\n return packedFileByName;\n}\n","import { createLogger } from \"~/utils\";\nimport { getConfig } from \"./config\";\nimport { PackagesRegistry } from \"./create-packages-registry\";\n\nexport function patchWorkspaceEntries(\n dependencies: Record<string, string>,\n packagesRegistry: PackagesRegistry,\n) {\n const log = createLogger(getConfig().logLevel);\n const allWorkspacePackageNames = Object.keys(packagesRegistry);\n\n return Object.fromEntries(\n Object.entries(dependencies).map(([key, value]) => {\n if (allWorkspacePackageNames.includes(key)) {\n const def = packagesRegistry[key];\n\n /**\n * The rootRelativeDir is the package location in the monorepo. In the\n * isolate folder we keep the same structure so we can use the same\n * relative path.\n */\n log.debug(`Linking dependency ${key} to file:${def.rootRelativeDir}`);\n\n return [key, `file:${def.rootRelativeDir}`];\n } else {\n return [key, value];\n }\n }),\n );\n}\n","import fs from \"fs-extra\";\nimport path from \"node:path\";\nimport { PackageManager } from \"~/helpers\";\nimport { pack, unpack } from \"~/utils\";\n\nexport async function processBuildOutputFiles({\n targetPackageDir,\n tmpDir,\n packageManager,\n isolateDir,\n}: {\n targetPackageDir: string;\n tmpDir: string;\n packageManager: PackageManager;\n isolateDir: string;\n}) {\n const packedFilePath = await pack(targetPackageDir, tmpDir, packageManager);\n const unpackDir = path.join(tmpDir, \"target\");\n await unpack(packedFilePath, unpackDir);\n await fs.copy(path.join(unpackDir, \"package\"), isolateDir);\n}\n","import fs from \"fs-extra\";\nimport assert from \"node:assert\";\nimport path from \"node:path\";\nimport { createLogger, readTypedYamlSync, writeTypedYamlSync } from \"~/utils\";\nimport { getConfig } from \"./config\";\nimport { PackagesRegistry } from \"./create-packages-registry\";\nimport { PackageManager } from \"./detect-package-manager\";\n\ntype PackagePath = string;\n\ntype PnpmLockfile = {\n lockfileVersion: string;\n importers: Record<\n PackagePath,\n {\n dependencies?: Record<string, unknown>;\n devDependencies?: Record<string, unknown>;\n }\n >;\n};\n\nexport function getLockfileFileName(packageManager: PackageManager) {\n switch (packageManager) {\n case \"pnpm\":\n return \"pnpm-lock.yaml\";\n case \"yarn\":\n return \"yarn.lock\";\n case \"npm\":\n return \"package-lock.json\";\n }\n}\n\n/**\n * Adapt the lockfile and write it to the isolate directory. Because we keep the\n * structure of packages in the isolate directory the same as they were in the\n * monorepo, the lockfile is largely still correct. The only things that need to\n * be done is to remove the root dependencies and devDependencies, and rename\n * the path to the target package to act as the new root.\n */\nexport function processLockfile({\n workspaceRootDir,\n targetPackageName,\n packagesRegistry,\n isolateDir,\n packageManager,\n}: {\n workspaceRootDir: string;\n targetPackageName: string;\n packagesRegistry: PackagesRegistry;\n isolateDir: string;\n packageManager: PackageManager;\n}) {\n const log = createLogger(getConfig().logLevel);\n\n const targetPackageRelativeDir =\n packagesRegistry[targetPackageName].rootRelativeDir;\n\n const fileName = getLockfileFileName(packageManager);\n\n const lockfileSrcPath = path.join(workspaceRootDir, fileName);\n const lockfileDstPath = path.join(isolateDir, fileName);\n\n switch (packageManager) {\n /**\n * It seems that for Yarn v1 and NPM v3 lockfile the content is not\n * dependent on the workspace packages structure, so I am assuming we can\n * just copy it over.\n */\n case \"npm\":\n case \"yarn\": {\n fs.copyFileSync(lockfileSrcPath, lockfileDstPath);\n log.debug(\"Copied lockfile to\", lockfileDstPath);\n return;\n }\n case \"pnpm\": {\n const origLockfile = readTypedYamlSync<PnpmLockfile>(lockfileSrcPath);\n\n log.debug(\"Read PNPM lockfile, version:\", origLockfile.lockfileVersion);\n\n const adaptedLockfile = structuredClone(origLockfile);\n\n const targetPackageDef =\n adaptedLockfile.importers[targetPackageRelativeDir];\n\n assert(\n targetPackageDef,\n `Failed to find target package in lockfile at importers[${targetPackageRelativeDir}]`\n );\n /**\n * Overwrite the root importer with the target package importer contents\n */\n adaptedLockfile.importers[\".\"] = targetPackageDef;\n\n /**\n * Delete the target package original importer. Not really necessary.\n */\n delete adaptedLockfile.importers[targetPackageRelativeDir];\n\n writeTypedYamlSync(lockfileDstPath, adaptedLockfile);\n\n log.debug(\"Stored adapted lockfile at\", lockfileDstPath);\n\n return;\n }\n\n // case \"npm\": {\n // /**\n // * Assuming a v3 lockfile.\n // */\n // const origLockfile = readTypedJsonSync<NpmLockfile_v3>(lockfileSrcPath);\n\n // /**\n // * Overwrite the root importer with the target package importer contents\n // */\n // const adaptedLockfile = structuredClone(origLockfile);\n\n // const targetPackageDef =\n // adaptedLockfile.packages[targetPackageRelativeDir];\n\n // assert(\n // targetPackageDef,\n // `Failed to find target package in lockfile at packages[${targetPackageRelativeDir}]`\n // );\n\n // /**\n // * The root in the NPM lockfile seems to be marked by an empty string\n // */\n // adaptedLockfile.packages[\"\"] = targetPackageDef;\n\n // /**\n // * Delete the target package original importer. Not really necessary.\n // */\n // delete adaptedLockfile.packages[targetPackageRelativeDir];\n\n // writeTypedYamlSync(lockfileDstPath, adaptedLockfile);\n\n // log.debug(\"Stored adapted lockfile at\", lockfileDstPath);\n // }\n }\n}\n","import fs from \"fs-extra\";\nimport path, { join } from \"node:path\";\nimport { getRelativePath } from \"~/utils\";\nimport { createLogger } from \"~/utils/logger\";\nimport { PackagesRegistry, getConfig } from \".\";\nimport { unpack } from \"../utils/unpack\";\n\nexport async function unpackDependencies(\n packedFilesByName: Record<string, string>,\n packagesRegistry: PackagesRegistry,\n tmpDir: string,\n isolateDir: string,\n) {\n const log = createLogger(getConfig().logLevel);\n await Promise.all(\n Object.entries(packedFilesByName).map(async ([packageName, filePath]) => {\n const dir = packagesRegistry[packageName].rootRelativeDir;\n\n const unpackDir = join(tmpDir, dir);\n\n await unpack(filePath, unpackDir);\n\n log.debug(\"Unpacked\", path.basename(filePath));\n\n const destinationDir = join(isolateDir, dir);\n\n await fs.ensureDir(destinationDir);\n\n await fs.move(join(unpackDir, \"package\"), destinationDir, {\n overwrite: true,\n });\n\n log.debug(\n `Moved package files to isolate ${getRelativePath(\n destinationDir,\n isolateDir,\n )}`,\n );\n }),\n );\n}\n"],"mappings":";;;AAEA,OAAOA,UAAQ;AACf,OAAOC,aAAY;AACnB,OAAOC,YAAU;AACjB,OAAO,gBAAgB;;;ACLvB,OAAO,QAAQ;AACf,OAAO,UAAU;AAOjB,eAAsB,mBACpB,mBACA,kBACA,YACA;AACA,QAAM,QAA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AAkB;AAAA,IAC1E,wBAAwB,OAAO;AAAA,EACjC,CAAC;AAED,QAAM,oBAAoB,MAAM,iBAAiB;AAAA,IAC/C;AAAA,IACA;AAAA,IACA,oBAAoB;AAAA,IACpB;AAAA,EACF,CAAC;AAED,QAAM;AAAA,IACJ;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AAKA,QAAM,mBAAmB,mBAAmB,kBAAkB,UAAU;AAKxE,QAAM,wBAAwB;AAAA,IAC5B;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF,CAAC;AAMD,QAAM,2BAA2B,UAAU,kBAAkB,UAAU;AAKvE,QAAM,gBAAgB;AAAA,IACpB;AAAA,IACA,mBAAmB,SAAS;AAAA,IAC5B;AAAA,IACA;AAAA,IACA;AAAA,EACF,CAAC;AAKD,MAAI;AAAA,IACF;AAAA,IACA,gBAAgB,QAAQ,gBAAgB;AAAA,EAC1C;AACA,QAAMD,KAAG,OAAO,MAAM;AAEtB,MAAI;AAAA,IACF;AAAA,IACAC,OAAK,KAAK,MAAM,gBAAgB,YAAY,gBAAgB,CAAC;AAAA,EAC/D;AACF;AAEA,MAAM,EAAE,MAAM,CAAC,QAAQ;AACrB,MAAI,eAAe,OAAO;AACxB,QAAI,MAAM,IAAI,KAAK;AACnB,YAAQ,KAAK,CAAC;AAAA,EAChB,OAAO;AACL,YAAQ,MAAM,GAAG;AAAA,EACnB;AACF,CAAC;AAED,QAAQ,GAAG,sBAAsB,IAAI,KAAK;","names":["fs","assert","path","path","fs","path","log","stdout","path","fs","fs","fs","path","fs","path","fs","path","log","path","fs","config","fs","path","path","fs","path","log","path","log","fs","path","fs","path","process","config","log","path","fs","process","path","config","log","log","fs","path","path","fs","fs","assert","path","log","path","fs","assert","fs","path","log","path","fs","assert","fs","path"]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/helpers/adapt-manifest-files.ts","../src/helpers/adapt-manifest-workspace-deps.ts","../src/utils/filter-object-undefined.ts","../src/utils/get-relative-path.ts","../src/utils/inspect-value.ts","../src/utils/json.ts","../src/utils/logger.ts","../src/utils/pack.ts","../src/utils/unpack.ts","../src/utils/yaml.ts","../src/helpers/adapt-target-package-manifest.ts","../src/helpers/config.ts","../src/helpers/create-packages-registry.ts","../src/helpers/find-packages-globs.ts","../src/helpers/detect-package-manager.ts","../src/helpers/get-build-output-dir.ts","../src/helpers/list-local-dependencies.ts","../src/helpers/manifest.ts","../src/helpers/pack-dependencies.ts","../src/helpers/patch-workspace-entries.ts","../src/helpers/process-build-output-files.ts","../src/helpers/process-lockfile.ts","../src/helpers/unpack-dependencies.ts"],"sourcesContent":["#!/usr/bin/env node\n\nimport fs from \"fs-extra\";\nimport assert from \"node:assert\";\nimport path from \"node:path\";\nimport sourceMaps from \"source-map-support\";\nimport {\n PackageManifestMinimum,\n adaptManifestFiles,\n adaptTargetPackageManifest,\n createPackagesRegistry,\n detectPackageManager,\n getBuildOutputDir,\n getConfig,\n listLocalDependencies,\n packDependencies,\n processBuildOutputFiles,\n processLockfile,\n unpackDependencies,\n} from \"~/helpers\";\nimport { createLogger, getRelativePath, readTypedJson } from \"~/utils\";\n\nconst config = getConfig();\nconst log = createLogger(config.logLevel);\n\nsourceMaps.install();\n\nasync function start() {\n /**\n * If a targetPackagePath is set, we assume the configuration lives in the\n * root of the workspace. If targetPackagePath is undefined (the default), we\n * assume that the configuration lives in the target package directory.\n */\n const targetPackageDir = config.targetPackagePath\n ? path.join(process.cwd(), config.targetPackagePath)\n : process.cwd();\n\n /**\n * We want a trailing slash here. Functionally it doesn't matter, but it makes\n * the relative paths more correct in the debug output.\n */\n const workspaceRootDir = config.targetPackagePath\n ? process.cwd()\n : path.join(targetPackageDir, config.workspaceRoot);\n\n const buildOutputDir = await getBuildOutputDir(targetPackageDir);\n\n assert(\n fs.existsSync(buildOutputDir),\n `Failed to find build output path at ${buildOutputDir}. Please make sure you build the source before isolating it.`\n );\n\n log.debug(\"Workspace root\", workspaceRootDir);\n log.debug(\n \"Isolate target package\",\n getRelativePath(targetPackageDir, workspaceRootDir)\n );\n\n const packageManager = detectPackageManager(workspaceRootDir);\n\n const isolateDir = path.join(targetPackageDir, config.isolateDirName);\n\n log.debug(\n \"Isolate output dir\",\n getRelativePath(isolateDir, workspaceRootDir)\n );\n\n /**\n * Make sure the isolate dir exists so we can write to it\n */\n await fs.ensureDir(isolateDir);\n\n await fs.remove(`${isolateDir}/**/*`);\n log.debug(\"Cleaned the isolate output directory\");\n\n /**\n * Build a packages registry so we can find the workspace packages by name and\n * have access to their manifest files and relative paths.\n */\n const packagesRegistry = await createPackagesRegistry(\n workspaceRootDir,\n config.workspacePackages\n );\n\n const tmpDir = path.join(isolateDir, \"__tmp\");\n await fs.ensureDir(tmpDir);\n\n /**\n * PNPM pack seems to be much faster than NPM pack so we use that when PNPM is\n * detected. We log it here because the pack function will be called\n * recursively.\n */\n if (packageManager === \"pnpm\") {\n log.debug(\"Using pnpm to pack dependencies\");\n } else {\n log.debug(\"Using npm to pack dependencies\");\n }\n\n const manifest = await readTypedJson<PackageManifestMinimum>(\n path.join(targetPackageDir, \"package.json\")\n );\n\n const localDependencies = listLocalDependencies(manifest, packagesRegistry, {\n includeDevDependencies: config.includeDevDependencies,\n });\n\n const packedFilesByName = await packDependencies({\n localDependencies,\n packagesRegistry,\n packDestinationDir: tmpDir,\n packageManager,\n });\n\n await unpackDependencies(\n packedFilesByName,\n packagesRegistry,\n tmpDir,\n isolateDir\n );\n\n /**\n * Adapt the manifest files for all the unpacked local dependencies\n */\n await adaptManifestFiles(localDependencies, packagesRegistry, isolateDir);\n\n /**\n * Pack the target package directory, and unpack it in the isolate location\n */\n await processBuildOutputFiles({\n targetPackageDir,\n tmpDir,\n packageManager,\n isolateDir,\n });\n\n /**\n * Copy the target manifest file to the isolate location and adapt its\n * workspace dependencies to point to the isolated packages.\n */\n await adaptTargetPackageManifest(manifest, packagesRegistry, isolateDir);\n\n /**\n * Copy and adapt the lockfile\n */\n await processLockfile({\n workspaceRootDir,\n targetPackageName: manifest.name,\n isolateDir,\n packagesRegistry,\n packageManager,\n });\n\n /**\n * Clean up. Only so this in the happy path, so we can look at the temp folder\n * when thing go wrong.\n */\n log.debug(\n \"Deleting temporary directory\",\n getRelativePath(tmpDir, workspaceRootDir)\n );\n await fs.remove(tmpDir);\n\n log.debug(\"Stored isolate output at\", isolateDir);\n\n log.info(\"Isolate completed\");\n}\n\nstart().catch((err) => {\n if (err instanceof Error) {\n log.error(err.stack);\n process.exit(1);\n } else {\n console.error(err);\n }\n});\n\nprocess.on(\"unhandledRejection\", log.error);\n","import fs from \"fs-extra\";\nimport path from \"node:path\";\nimport {\n PackagesRegistry,\n adaptManifestWorkspaceDeps,\n getConfig,\n} from \"~/helpers\";\n\nexport async function adaptManifestFiles(\n localDependencies: string[],\n packagesRegistry: PackagesRegistry,\n isolateDir: string,\n) {\n await Promise.all(\n localDependencies.map(async (packageName) => {\n const { manifest, rootRelativeDir } = packagesRegistry[packageName];\n\n const outputManifest = adaptManifestWorkspaceDeps(\n { manifest, packagesRegistry },\n { includeDevDependencies: getConfig().includeDevDependencies },\n );\n\n await fs.writeFile(\n path.join(isolateDir, rootRelativeDir, \"package.json\"),\n JSON.stringify(outputManifest, null, 2),\n );\n }),\n );\n}\n","import { omit } from \"lodash-es\";\nimport { filterObjectUndefined } from \"~/utils\";\nimport {\n PackageManifestMinimum,\n PackagesRegistry,\n patchWorkspaceEntries,\n} from \".\";\n\nexport function adaptManifestWorkspaceDeps(\n {\n manifest,\n packagesRegistry,\n }: {\n manifest: PackageManifestMinimum;\n packagesRegistry: PackagesRegistry;\n },\n opts: { includeDevDependencies?: boolean } = {},\n): PackageManifestMinimum {\n return Object.assign(\n omit(manifest, [\"scripts\", \"devDependencies\"]),\n filterObjectUndefined({\n dependencies: manifest.dependencies\n ? patchWorkspaceEntries(manifest.dependencies, packagesRegistry)\n : undefined,\n devDependencies:\n opts.includeDevDependencies && manifest.devDependencies\n ? patchWorkspaceEntries(manifest.devDependencies, packagesRegistry)\n : undefined,\n }),\n );\n}\n","export function filterObjectUndefined(object: Record<string, unknown>) {\n return Object.fromEntries(\n Object.entries(object).filter(([_, value]) => value !== undefined),\n );\n}\n","export function getRelativePath(path: string, relativeTo: string) {\n const strippedPath = path.replace(relativeTo, \"\");\n\n return strippedPath.startsWith(\"/\")\n ? `.${strippedPath}`\n : `./${strippedPath}`;\n}\n","import { inspect } from \"node:util\";\nimport { JsonValue } from \"type-fest\";\n\nexport function inspectValue(value: JsonValue) {\n return inspect(value, false, 4, true);\n}\n","import fs from \"fs-extra\";\n\n/**\n * @TODO pass in zod schema and validate\n */\nexport function readTypedJsonSync<T>(filePath: string) {\n const rawContent = fs.readFileSync(filePath, \"utf-8\");\n const data = JSON.parse(rawContent) as T;\n return data;\n}\n\nexport async function readTypedJson<T>(filePath: string) {\n const rawContent = await fs.readFile(filePath, \"utf-8\");\n const data = JSON.parse(rawContent) as T;\n return data;\n}\n","import chalk from \"chalk\";\nimport { IsolateConfigResolved } from \"~/helpers\";\n\nexport type Logger = {\n debug(...args: any[]): void;\n info(...args: any[]): void;\n warn(...args: any[]): void;\n error(...args: any[]): void;\n};\n\nexport function createLogger(\n logLevel: IsolateConfigResolved[\"logLevel\"]\n): Logger {\n return {\n debug(...args: any[]) {\n if (logLevel === \"debug\") {\n console.log(chalk.blue(\"debug\"), ...args);\n }\n },\n info(...args: any[]) {\n if (logLevel === \"debug\" || logLevel === \"info\") {\n console.log(chalk.green(\"info\"), ...args);\n }\n },\n warn(...args: any[]) {\n if (logLevel === \"debug\" || logLevel === \"info\" || logLevel === \"warn\") {\n console.log(chalk.yellow(\"warning\"), ...args);\n }\n },\n error(...args: any[]) {\n console.log(chalk.red(\"error\"), ...args);\n },\n };\n}\n","import { exec } from \"node:child_process\";\nimport path from \"node:path\";\nimport { PackageManager, getConfig } from \"~/helpers\";\nimport { createLogger } from \"./logger\";\n\nexport async function pack(\n srcDir: string,\n destDir: string,\n packageManager: PackageManager,\n) {\n const log = createLogger(getConfig().logLevel);\n const cwd = process.cwd();\n process.chdir(srcDir);\n\n /**\n * PNPM pack seems to be a lot faster than NPM pack, so when PNPM is detected we\n * use that instead.\n */\n switch (packageManager) {\n case \"pnpm\": {\n const stdout = await new Promise<string>((resolve, reject) => {\n exec(`pnpm pack --pack-destination ${destDir}`, (err, stdout) => {\n if (err) {\n return reject(err);\n }\n\n resolve(stdout);\n });\n });\n\n /**\n * Trim newlines and whitespace\n */\n const packedFilePath = stdout.trim();\n\n log.debug(\"Packed\", path.basename(packedFilePath));\n\n process.chdir(cwd);\n return packedFilePath;\n }\n\n case \"yarn\":\n case \"npm\": {\n const stdout = await new Promise<string>((resolve, reject) => {\n exec(`npm pack --pack-destination ${destDir}`, (err, stdout) => {\n if (err) {\n return reject(err);\n }\n\n resolve(stdout);\n });\n });\n\n /**\n * Trim newlines and whitespace\n */\n const packedFileName = stdout.trim();\n\n log.debug(\"Packed\", packedFileName);\n\n process.chdir(cwd);\n return path.join(destDir, packedFileName);\n }\n }\n}\n","import fs from \"fs-extra\";\nimport tar from \"tar-fs\";\nimport { createGunzip } from \"zlib\";\n\nexport async function unpack(filePath: string, unpackDir: string) {\n await new Promise<void>((resolve, reject) => {\n fs.createReadStream(filePath)\n .pipe(createGunzip())\n .pipe(tar.extract(unpackDir))\n .on(\"finish\", () => resolve())\n .on(\"error\", (err) => reject(err));\n });\n}\n","import fs from \"fs-extra\";\nimport yaml from \"yaml\";\n\nexport function readTypedYamlSync<T>(filePath: string) {\n const rawContent = fs.readFileSync(filePath, \"utf-8\");\n const data = yaml.parse(rawContent);\n /**\n * @TODO add some zod validation maybe\n */\n return data as T;\n}\n\nexport function writeTypedYamlSync<T>(filePath: string, content: T) {\n /**\n * @TODO add some zod validation maybe\n */\n fs.writeFileSync(filePath, yaml.stringify(content), \"utf-8\");\n}\n","import fs from \"fs-extra\";\nimport path from \"node:path\";\nimport {\n PackageManifestMinimum,\n PackagesRegistry,\n adaptManifestWorkspaceDeps,\n getConfig,\n} from \"~/helpers\";\n\nexport async function adaptTargetPackageManifest(\n manifest: PackageManifestMinimum,\n packagesRegistry: PackagesRegistry,\n isolateDir: string,\n) {\n const outputManifest = adaptManifestWorkspaceDeps(\n {\n manifest,\n packagesRegistry,\n },\n { includeDevDependencies: getConfig().includeDevDependencies },\n );\n\n await fs.writeFile(\n path.join(isolateDir, \"package.json\"),\n JSON.stringify(outputManifest, null, 2),\n );\n}\n","import fs from \"fs-extra\";\nimport { isEmpty } from \"lodash-es\";\nimport path from \"node:path\";\nimport { createLogger, inspectValue, readTypedJsonSync } from \"~/utils\";\n\nexport type IsolateConfigResolved = {\n buildDirName?: string;\n includeDevDependencies: boolean;\n isolateDirName: string;\n logLevel: \"info\" | \"debug\" | \"warn\" | \"error\";\n targetPackagePath?: string;\n tsconfigPath: string;\n workspacePackages?: string[];\n workspaceRoot: string;\n};\n\nexport type IsolateConfig = Partial<IsolateConfigResolved>;\n\nconst configDefaults: IsolateConfigResolved = {\n buildDirName: undefined,\n includeDevDependencies: false,\n isolateDirName: \"isolate\",\n logLevel: \"info\",\n targetPackagePath: undefined,\n tsconfigPath: \"./tsconfig.json\",\n workspacePackages: undefined,\n workspaceRoot: \"../..\",\n};\n\n/**\n * Only initialize the configuration once, and keeping it here for subsequent\n * calls to getConfig.\n */\nlet __config: IsolateConfigResolved | undefined;\n\nconst validConfigKeys = Object.keys(configDefaults);\n\nconst CONFIG_FILE_NAME = \"isolate.config.json\";\n\ntype LogLevel = IsolateConfigResolved[\"logLevel\"];\n\nexport function getConfig(): IsolateConfigResolved {\n if (__config) {\n return __config;\n }\n\n /**\n * Since the logLevel is set via config we can't use it to determine if we\n * should output verbose logging as part of the config loading process. Using\n * the env var ISOLATE_CONFIG_LOG_LEVEL you have the option to log debug\n * output.\n */\n const log = createLogger(\n (process.env.ISOLATE_CONFIG_LOG_LEVEL as LogLevel) ?? \"warn\"\n );\n\n const configFilePath = path.join(process.cwd(), CONFIG_FILE_NAME);\n\n log.debug(`Attempting to load config from ${configFilePath}`);\n\n const configFromFile = fs.existsSync(configFilePath)\n ? readTypedJsonSync<IsolateConfig>(configFilePath)\n : {};\n\n const foreignKeys = Object.keys(configFromFile).filter(\n (key) => !validConfigKeys.includes(key)\n );\n\n if (!isEmpty(foreignKeys)) {\n log.warn(`Found invalid config settings:`, foreignKeys.join(\", \"));\n }\n\n const config = Object.assign(\n {},\n configDefaults,\n configFromFile\n ) satisfies IsolateConfigResolved;\n\n log.debug(\"Using configuration:\", inspectValue(config));\n\n __config = config;\n return config;\n}\n","import fs from \"fs-extra\";\nimport { globSync } from \"glob\";\nimport { set } from \"lodash-es\";\nimport path from \"node:path\";\nimport { createLogger, readTypedJson } from \"~/utils\";\nimport { getConfig } from \"./config\";\nimport { findPackagesGlobs } from \"./find-packages-globs\";\n\nexport type PackageManifestMinimum = {\n name: string;\n dependencies?: Record<string, string>;\n devDependencies?: Record<string, string>;\n main: string;\n module?: string;\n exports?: Record<string, { require: string; import: string }>;\n files: string[];\n version?: string;\n typings?: string;\n scripts?: Record<string, string>;\n};\n\nexport type WorkspacePackageInfo = {\n absoluteDir: string;\n /**\n * The path of the package relative to the workspace root. This is the path\n * referenced in the lock file.\n */\n rootRelativeDir: string;\n /**\n * The package.json file contents\n */\n manifest: PackageManifestMinimum;\n};\n\nexport type PackagesRegistry = Record<string, WorkspacePackageInfo>;\n\n/**\n * Build a list of all packages in the workspace, depending on the package\n * manager used, with a possible override from the config file. The list contains\n * the manifest with some directory info mapped by module name.\n */\nexport async function createPackagesRegistry(\n workspaceRootDir: string,\n workspacePackagesOverride: string[] | undefined\n): Promise<PackagesRegistry> {\n const log = createLogger(getConfig().logLevel);\n\n if (workspacePackagesOverride) {\n log.debug(\n `Override workspace packages via config: ${workspacePackagesOverride}`\n );\n }\n\n const packagesGlobs =\n workspacePackagesOverride ?? findPackagesGlobs(workspaceRootDir);\n\n const cwd = process.cwd();\n process.chdir(workspaceRootDir);\n\n const allPackages = packagesGlobs\n .flatMap((glob) => globSync(glob))\n /**\n * Make sure to filter any loose files that might hang around.\n */\n .filter((dir) => fs.lstatSync(dir).isDirectory());\n\n const registry: PackagesRegistry = (\n await Promise.all(\n allPackages.map(async (rootRelativeDir) => {\n const manifestPath = path.join(rootRelativeDir, \"package.json\");\n\n if (!fs.existsSync(manifestPath)) {\n log.warn(\n `Ignoring directory ./${rootRelativeDir} because it does not contain a package.json file`\n );\n return;\n } else {\n log.debug(`Registering package ./${rootRelativeDir}`);\n\n const manifest = await readTypedJson<PackageManifestMinimum>(\n path.join(rootRelativeDir, \"package.json\")\n );\n\n return {\n manifest,\n rootRelativeDir,\n absoluteDir: path.join(workspaceRootDir, rootRelativeDir),\n };\n }\n })\n )\n ).reduce<PackagesRegistry>(\n (acc, info) => (info ? set(acc, info.manifest.name, info) : acc),\n {}\n );\n\n process.chdir(cwd);\n\n return registry;\n}\n","import path from \"node:path\";\nimport {\n createLogger,\n inspectValue,\n readTypedJsonSync,\n readTypedYamlSync,\n} from \"~/utils\";\nimport { getConfig } from \"./config\";\nimport { detectPackageManager } from \"./detect-package-manager\";\n\n/**\n * Find the globs that define where the packages are located within the\n * monorepo. This configuration is dependent on the package manager used, and I\n * don't know if we're covering all cases yet...\n */\nexport function findPackagesGlobs(workspaceRootDir: string) {\n const log = createLogger(getConfig().logLevel);\n\n const packageManager = detectPackageManager(workspaceRootDir);\n\n switch (packageManager) {\n case \"pnpm\": {\n const { packages: globs } = readTypedYamlSync<{ packages: string[] }>(\n path.join(workspaceRootDir, \"pnpm-workspace.yaml\")\n );\n\n log.debug(\"Detected pnpm packages globs:\", inspectValue(globs));\n return globs;\n }\n case \"yarn\":\n case \"npm\": {\n const workspaceRootManifestPath = path.join(\n workspaceRootDir,\n \"package.json\"\n );\n\n const { workspaces } = readTypedJsonSync<{ workspaces: string[] }>(\n workspaceRootManifestPath\n );\n\n if (!workspaces) {\n throw new Error(\n `No workspaces field found in ${workspaceRootManifestPath}`\n );\n }\n\n return workspaces;\n }\n }\n}\n","import fs from \"fs-extra\";\nimport path from \"node:path\";\n\nexport type PackageManager = \"pnpm\" | \"yarn\" | \"npm\";\n\nexport function detectPackageManager(workspaceRoot: string): PackageManager {\n if (fs.existsSync(path.join(workspaceRoot, \"pnpm-lock.yaml\"))) {\n return \"pnpm\";\n }\n\n if (fs.existsSync(path.join(workspaceRoot, \"yarn.lock\"))) {\n return \"yarn\";\n }\n\n if (fs.existsSync(path.join(workspaceRoot, \"package-lock.json\"))) {\n return \"npm\";\n }\n\n throw new Error(`Failed to detect package manager`);\n}\n","import fs from \"fs-extra\";\nimport path from \"node:path\";\nimport outdent from \"outdent\";\nimport { getConfig } from \"~/helpers\";\nimport { createLogger, readTypedJson } from \"~/utils\";\n\nexport async function getBuildOutputDir(targetPackageDir: string) {\n const config = getConfig();\n const log = createLogger(getConfig().logLevel);\n\n if (config.buildDirName) {\n log.debug(\"Using buildDirName from config:\", config.buildDirName);\n return path.join(targetPackageDir, config.buildDirName);\n }\n\n const tsconfigPath = path.join(targetPackageDir, config.tsconfigPath);\n\n log.debug(\"Looking for tsconfig at:\", tsconfigPath);\n\n if (fs.existsSync(tsconfigPath)) {\n const tsconfig = await readTypedJson<{\n compilerOptions?: { outDir?: string };\n }>(tsconfigPath);\n\n const outDir = tsconfig.compilerOptions?.outDir;\n\n if (outDir) {\n return path.join(targetPackageDir, outDir);\n } else {\n throw new Error(outdent`\n 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.\n `);\n }\n } else {\n throw new Error(outdent`\n 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.\n `);\n }\n}\n","import {\n PackageManifestMinimum,\n PackagesRegistry,\n} from \"./create-packages-registry\";\n\n/**\n * Recursively list the packages from dependencies (and optionally\n * devDependencies) that are found in the workspace.\n *\n * Here we do not need to rely on packages being declared as \"workspace:\" in the\n * manifest. We can simply compare the package names with the list of packages\n * that were found via the workspace glob patterns and added to the registry.\n */\nexport function listLocalDependencies(\n manifest: PackageManifestMinimum,\n packagesRegistry: PackagesRegistry,\n { includeDevDependencies = false } = {},\n): string[] {\n const allWorkspacePackageNames = Object.keys(packagesRegistry);\n\n const localDependencyPackageNames = (\n includeDevDependencies\n ? [\n ...Object.keys(manifest.dependencies ?? {}),\n ...Object.keys(manifest.devDependencies ?? {}),\n ]\n : Object.keys(manifest.dependencies ?? {})\n ).filter((name) => allWorkspacePackageNames.includes(name));\n\n const nestedLocalDependencies = localDependencyPackageNames.flatMap(\n (packageName) =>\n listLocalDependencies(\n packagesRegistry[packageName].manifest,\n packagesRegistry,\n { includeDevDependencies },\n ),\n );\n\n return localDependencyPackageNames.concat(nestedLocalDependencies);\n}\n","import path from \"node:path\";\nimport { readTypedJson } from \"~/utils\";\nimport { PackageManifestMinimum } from \"./create-packages-registry\";\n\nexport async function importManifest(packageDir: string) {\n return readTypedJson<PackageManifestMinimum>(\n path.join(packageDir, \"package.json\"),\n );\n}\n","import assert from \"node:assert\";\nimport { createLogger, pack } from \"~/utils\";\nimport { getConfig } from \"./config\";\nimport { PackagesRegistry } from \"./create-packages-registry\";\nimport { PackageManager } from \"./detect-package-manager\";\n\n/**\n * Pack dependencies so that we extract only the files that are supposed to be\n * published by the packages.\n *\n * @returns A map of package names to the path of the packed file\n */\nexport async function packDependencies({\n /**\n * All packages found in the monorepo by workspaces declaration\n */\n packagesRegistry,\n /**\n * The package names that appear to be local dependencies\n */\n localDependencies,\n /**\n * The directory where the isolated package and all its dependencies will end\n * up. This is also the directory from where the package will be deployed. By\n * default it is a subfolder in targetPackageDir called \"isolate\" but you can\n * configure it.\n */\n packDestinationDir,\n\n packageManager,\n}: {\n packagesRegistry: PackagesRegistry;\n localDependencies: string[];\n packDestinationDir: string;\n packageManager: PackageManager;\n}) {\n const config = getConfig();\n const log = createLogger(config.logLevel);\n\n const packedFileByName: Record<string, string> = {};\n\n for (const dependency of localDependencies) {\n const def = packagesRegistry[dependency];\n\n assert(dependency, `Failed to find package definition for ${dependency}`);\n\n const { name } = def.manifest;\n\n /**\n * If this dependency has already been packed, we skip it. It could happen\n * because we are packing workspace dependencies recursively.\n */\n if (packedFileByName[name]) {\n log.debug(`Skipping ${name} because it has already been packed`);\n continue;\n }\n\n packedFileByName[name] = await pack(\n def.absoluteDir,\n packDestinationDir,\n packageManager,\n );\n\n /**\n * @TODO call recursively\n */\n }\n\n return packedFileByName;\n}\n","import { createLogger } from \"~/utils\";\nimport { getConfig } from \"./config\";\nimport { PackagesRegistry } from \"./create-packages-registry\";\n\nexport function patchWorkspaceEntries(\n dependencies: Record<string, string>,\n packagesRegistry: PackagesRegistry,\n) {\n const log = createLogger(getConfig().logLevel);\n const allWorkspacePackageNames = Object.keys(packagesRegistry);\n\n return Object.fromEntries(\n Object.entries(dependencies).map(([key, value]) => {\n if (allWorkspacePackageNames.includes(key)) {\n const def = packagesRegistry[key];\n\n /**\n * The rootRelativeDir is the package location in the monorepo. In the\n * isolate folder we keep the same structure so we can use the same\n * relative path.\n */\n log.debug(`Linking dependency ${key} to file:${def.rootRelativeDir}`);\n\n return [key, `file:${def.rootRelativeDir}`];\n } else {\n return [key, value];\n }\n }),\n );\n}\n","import fs from \"fs-extra\";\nimport path from \"node:path\";\nimport { PackageManager } from \"~/helpers\";\nimport { pack, unpack } from \"~/utils\";\n\nexport async function processBuildOutputFiles({\n targetPackageDir,\n tmpDir,\n packageManager,\n isolateDir,\n}: {\n targetPackageDir: string;\n tmpDir: string;\n packageManager: PackageManager;\n isolateDir: string;\n}) {\n const packedFilePath = await pack(targetPackageDir, tmpDir, packageManager);\n const unpackDir = path.join(tmpDir, \"target\");\n await unpack(packedFilePath, unpackDir);\n await fs.copy(path.join(unpackDir, \"package\"), isolateDir);\n}\n","import fs from \"fs-extra\";\nimport assert from \"node:assert\";\nimport path from \"node:path\";\nimport { createLogger, readTypedYamlSync, writeTypedYamlSync } from \"~/utils\";\nimport { getConfig } from \"./config\";\nimport { PackagesRegistry } from \"./create-packages-registry\";\nimport { PackageManager } from \"./detect-package-manager\";\n\ntype PackagePath = string;\n\ntype PnpmLockfile = {\n lockfileVersion: string;\n importers: Record<\n PackagePath,\n {\n dependencies?: Record<string, unknown>;\n devDependencies?: Record<string, unknown>;\n }\n >;\n};\n\nexport function getLockfileFileName(packageManager: PackageManager) {\n switch (packageManager) {\n case \"pnpm\":\n return \"pnpm-lock.yaml\";\n case \"yarn\":\n return \"yarn.lock\";\n case \"npm\":\n return \"package-lock.json\";\n }\n}\n\n/**\n * Adapt the lockfile and write it to the isolate directory. Because we keep the\n * structure of packages in the isolate directory the same as they were in the\n * monorepo, the lockfile is largely still correct. The only things that need to\n * be done is to remove the root dependencies and devDependencies, and rename\n * the path to the target package to act as the new root.\n */\nexport function processLockfile({\n workspaceRootDir,\n targetPackageName,\n packagesRegistry,\n isolateDir,\n packageManager,\n}: {\n workspaceRootDir: string;\n targetPackageName: string;\n packagesRegistry: PackagesRegistry;\n isolateDir: string;\n packageManager: PackageManager;\n}) {\n const log = createLogger(getConfig().logLevel);\n\n const targetPackageRelativeDir =\n packagesRegistry[targetPackageName].rootRelativeDir;\n\n const fileName = getLockfileFileName(packageManager);\n\n const lockfileSrcPath = path.join(workspaceRootDir, fileName);\n const lockfileDstPath = path.join(isolateDir, fileName);\n\n switch (packageManager) {\n /**\n * It seems that for Yarn v1 and NPM v3 lockfile the content is not\n * dependent on the workspace packages structure, so I am assuming we can\n * just copy it over.\n */\n case \"npm\":\n case \"yarn\": {\n fs.copyFileSync(lockfileSrcPath, lockfileDstPath);\n log.debug(\"Copied lockfile to\", lockfileDstPath);\n return;\n }\n case \"pnpm\": {\n const origLockfile = readTypedYamlSync<PnpmLockfile>(lockfileSrcPath);\n\n log.debug(\"Read PNPM lockfile, version:\", origLockfile.lockfileVersion);\n\n const adaptedLockfile = structuredClone(origLockfile);\n\n const targetPackageDef =\n adaptedLockfile.importers[targetPackageRelativeDir];\n\n assert(\n targetPackageDef,\n `Failed to find target package in lockfile at importers[${targetPackageRelativeDir}]`\n );\n /**\n * Overwrite the root importer with the target package importer contents\n */\n adaptedLockfile.importers[\".\"] = targetPackageDef;\n\n /**\n * Delete the target package original importer. Not really necessary.\n */\n delete adaptedLockfile.importers[targetPackageRelativeDir];\n\n writeTypedYamlSync(lockfileDstPath, adaptedLockfile);\n\n log.debug(\"Stored adapted lockfile at\", lockfileDstPath);\n\n return;\n }\n\n // case \"npm\": {\n // /**\n // * Assuming a v3 lockfile.\n // */\n // const origLockfile = readTypedJsonSync<NpmLockfile_v3>(lockfileSrcPath);\n\n // /**\n // * Overwrite the root importer with the target package importer contents\n // */\n // const adaptedLockfile = structuredClone(origLockfile);\n\n // const targetPackageDef =\n // adaptedLockfile.packages[targetPackageRelativeDir];\n\n // assert(\n // targetPackageDef,\n // `Failed to find target package in lockfile at packages[${targetPackageRelativeDir}]`\n // );\n\n // /**\n // * The root in the NPM lockfile seems to be marked by an empty string\n // */\n // adaptedLockfile.packages[\"\"] = targetPackageDef;\n\n // /**\n // * Delete the target package original importer. Not really necessary.\n // */\n // delete adaptedLockfile.packages[targetPackageRelativeDir];\n\n // writeTypedYamlSync(lockfileDstPath, adaptedLockfile);\n\n // log.debug(\"Stored adapted lockfile at\", lockfileDstPath);\n // }\n }\n}\n","import fs from \"fs-extra\";\nimport path, { join } from \"node:path\";\nimport { getRelativePath } from \"~/utils\";\nimport { createLogger } from \"~/utils/logger\";\nimport { PackagesRegistry, getConfig } from \".\";\nimport { unpack } from \"../utils/unpack\";\n\nexport async function unpackDependencies(\n packedFilesByName: Record<string, string>,\n packagesRegistry: PackagesRegistry,\n tmpDir: string,\n isolateDir: string\n) {\n const log = createLogger(getConfig().logLevel);\n await Promise.all(\n Object.entries(packedFilesByName).map(async ([packageName, filePath]) => {\n const dir = packagesRegistry[packageName].rootRelativeDir;\n\n const unpackDir = join(tmpDir, dir);\n\n log.debug(\"Unpacking\", path.basename(filePath));\n\n await unpack(filePath, unpackDir);\n\n const destinationDir = join(isolateDir, dir);\n\n await fs.ensureDir(destinationDir);\n\n await fs.move(join(unpackDir, \"package\"), destinationDir, {\n overwrite: true,\n });\n\n log.debug(\n `Moved package files to isolate ${getRelativePath(\n destinationDir,\n isolateDir\n )}`\n );\n })\n );\n}\n"],"mappings":";;;AAEA,OAAOA,UAAQ;AACf,OAAOC,aAAY;AACnB,OAAOC,YAAU;AACjB,OAAO,gBAAgB;;;ACLvB,OAAO,QAAQ;AACf,OAAO,UAAU;AAOjB,eAAsB,mBACpB,mBACA,kBACA,YACA;AACA,QAAM,QAAQ;AAAA,IACZ,kBAAkB,IAAI,OAAO,gBAAgB;AAC3C,YAAM,EAAE,UAAU,gBAAgB,IAAI,iBAAiB,WAAW;AAElE,YAAM,iBAAiB;AAAA,QACrB,EAAE,UAAU,iBAAiB;AAAA,QAC7B,EAAE,wBAAwB,UAAU,EAAE,uBAAuB;AAAA,MAC/D;AAEA,YAAM,GAAG;AAAA,QACP,KAAK,KAAK,YAAY,iBAAiB,cAAc;AAAA,QACrD,KAAK,UAAU,gBAAgB,MAAM,CAAC;AAAA,MACxC;AAAA,IACF,CAAC;AAAA,EACH;AACF;;;AC5BA,SAAS,YAAY;;;ACAd,SAAS,sBAAsB,QAAiC;AACrE,SAAO,OAAO;AAAA,IACZ,OAAO,QAAQ,MAAM,EAAE,OAAO,CAAC,CAAC,GAAG,KAAK,MAAM,UAAU,MAAS;AAAA,EACnE;AACF;;;ACJO,SAAS,gBAAgBC,QAAc,YAAoB;AAChE,QAAM,eAAeA,OAAK,QAAQ,YAAY,EAAE;AAEhD,SAAO,aAAa,WAAW,GAAG,IAC9B,IAAI,iBACJ,KAAK;AACX;;;ACNA,SAAS,eAAe;AAGjB,SAAS,aAAa,OAAkB;AAC7C,SAAO,QAAQ,OAAO,OAAO,GAAG,IAAI;AACtC;;;ACLA,OAAOC,SAAQ;AAKR,SAAS,kBAAqB,UAAkB;AACrD,QAAM,aAAaA,IAAG,aAAa,UAAU,OAAO;AACpD,QAAM,OAAO,KAAK,MAAM,UAAU;AAClC,SAAO;AACT;AAEA,eAAsB,cAAiB,UA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I,KAAK,mBAAmB;AAC9B;AAEA,MAAM,EAAE,MAAM,CAAC,QAAQ;AACrB,MAAI,eAAe,OAAO;AACxB,QAAI,MAAM,IAAI,KAAK;AACnB,YAAQ,KAAK,CAAC;AAAA,EAChB,OAAO;AACL,YAAQ,MAAM,GAAG;AAAA,EACnB;AACF,CAAC;AAED,QAAQ,GAAG,sBAAsB,IAAI,KAAK;","names":["fs","assert","path","path","fs","path","log","stdout","path","fs","fs","fs","path","fs","path","fs","path","log","path","fs","config","fs","path","path","fs","path","log","path","log","fs","path","fs","path","config","log","path","fs","path","config","log","log","fs","path","path","fs","fs","assert","path","log","path","fs","assert","fs","path","log","path","fs","path","assert","fs"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "isolate-package",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"description": "Isolate a monorepo package by bundling the build output with its shared workspace packages and lock file to form a self-contained directory.",
|
|
5
5
|
"author": "Thijs Koerselman",
|
|
6
6
|
"license": "MIT",
|
|
@@ -29,6 +29,7 @@
|
|
|
29
29
|
"fs-extra": "^11.1.1",
|
|
30
30
|
"glob": "^10.2.2",
|
|
31
31
|
"lodash-es": "^4.17.21",
|
|
32
|
+
"outdent": "^0.8.0",
|
|
32
33
|
"source-map-support": "^0.5.21",
|
|
33
34
|
"tar-fs": "^2.1.1",
|
|
34
35
|
"yaml": "^2.2.2"
|