nf3 0.1.4 → 0.1.6
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 +39 -0
- package/dist/index.d.mts +34 -1
- package/dist/index.mjs +39 -12
- package/dist/node_modules/@isaacs/fs-minipass/dist/commonjs/index.js +1 -430
- package/dist/node_modules/@isaacs/fs-minipass/package.json +1 -54
- package/dist/node_modules/@mapbox/node-pre-gyp/lib/build.js +1 -51
- package/dist/node_modules/@mapbox/node-pre-gyp/lib/clean.js +1 -31
- package/dist/node_modules/@mapbox/node-pre-gyp/lib/configure.js +1 -52
- package/dist/node_modules/@mapbox/node-pre-gyp/lib/info.js +1 -37
- package/dist/node_modules/@mapbox/node-pre-gyp/lib/install.js +1 -234
- package/dist/node_modules/@mapbox/node-pre-gyp/lib/main.js +1 -125
- package/dist/node_modules/@mapbox/node-pre-gyp/lib/node-pre-gyp.js +3 -305
- package/dist/node_modules/@mapbox/node-pre-gyp/lib/package.js +1 -72
- package/dist/node_modules/@mapbox/node-pre-gyp/lib/pre-binding.js +1 -34
- package/dist/node_modules/@mapbox/node-pre-gyp/lib/publish.js +1 -80
- package/dist/node_modules/@mapbox/node-pre-gyp/lib/rebuild.js +1 -20
- package/dist/node_modules/@mapbox/node-pre-gyp/lib/reinstall.js +1 -19
- package/dist/node_modules/@mapbox/node-pre-gyp/lib/reveal.js +1 -32
- package/dist/node_modules/@mapbox/node-pre-gyp/lib/testbinary.js +1 -79
- package/dist/node_modules/@mapbox/node-pre-gyp/lib/testpackage.js +1 -52
- package/dist/node_modules/@mapbox/node-pre-gyp/lib/unpublish.js +1 -40
- package/dist/node_modules/@mapbox/node-pre-gyp/lib/util/compile.js +1 -93
- package/dist/node_modules/@mapbox/node-pre-gyp/lib/util/handle_gyp_opts.js +1 -102
- package/dist/node_modules/@mapbox/node-pre-gyp/lib/util/log.js +1 -9
- package/dist/node_modules/@mapbox/node-pre-gyp/lib/util/napi.js +1 -203
- package/dist/node_modules/@mapbox/node-pre-gyp/lib/util/s3_setup.js +2 -187
- package/dist/node_modules/@mapbox/node-pre-gyp/lib/util/versioning.js +4 -341
- package/dist/node_modules/@mapbox/node-pre-gyp/package.json +1 -59
- package/dist/node_modules/@rollup/pluginutils/dist/cjs/index.js +2 -407
- package/dist/node_modules/@rollup/pluginutils/package.json +0 -88
- package/dist/node_modules/@vercel/nft/out/analyze.js +1 -1073
- package/dist/node_modules/@vercel/nft/out/fs.js +1 -106
- package/dist/node_modules/@vercel/nft/out/index.js +1 -25
- package/dist/node_modules/@vercel/nft/out/node-file-trace.js +1 -369
- package/dist/node_modules/@vercel/nft/out/resolve-dependency.js +1 -334
- package/dist/node_modules/@vercel/nft/out/types.js +1 -2
- package/dist/node_modules/@vercel/nft/out/utils/ast-helpers.js +1 -49
- package/dist/node_modules/@vercel/nft/out/utils/binary-locators.js +1 -88
- package/dist/node_modules/@vercel/nft/out/utils/get-package-base.js +1 -30
- package/dist/node_modules/@vercel/nft/out/utils/interop-require.js +1 -24
- package/dist/node_modules/@vercel/nft/out/utils/node-version.js +1 -10
- package/dist/node_modules/@vercel/nft/out/utils/sharedlib-emit.js +1 -33
- package/dist/node_modules/@vercel/nft/out/utils/special-cases.js +1 -339
- package/dist/node_modules/@vercel/nft/out/utils/static-eval.js +1 -579
- package/dist/node_modules/@vercel/nft/out/utils/wrappers.js +1 -659
- package/dist/node_modules/@vercel/nft/package.json +1 -145
- package/dist/node_modules/abbrev/lib/index.js +1 -53
- package/dist/node_modules/abbrev/package.json +1 -41
- package/dist/node_modules/acorn/dist/acorn.js +9 -6262
- package/dist/node_modules/acorn/dist/acorn.mjs +9 -6233
- package/dist/node_modules/acorn/package.json +1 -35
- package/dist/node_modules/acorn-import-attributes/lib/index.js +1 -286
- package/dist/node_modules/acorn-import-attributes/package.json +1 -37
- package/dist/node_modules/async-sema/lib/index.js +1 -163
- package/dist/node_modules/async-sema/package.json +1 -49
- package/dist/node_modules/balanced-match/index.js +1 -62
- package/dist/node_modules/balanced-match/package.json +1 -44
- package/dist/node_modules/bindings/bindings.js +3 -221
- package/dist/node_modules/bindings/package.json +1 -24
- package/dist/node_modules/brace-expansion/index.js +1 -203
- package/dist/node_modules/brace-expansion/package.json +1 -45
- package/dist/node_modules/consola/dist/basic.cjs +1 -32
- package/dist/node_modules/consola/dist/core.cjs +4 -517
- package/dist/node_modules/consola/dist/shared/consola.DCGIlDNP.cjs +12 -75
- package/dist/node_modules/consola/package.json +1 -55
- package/dist/node_modules/detect-libc/lib/detect-libc.js +1 -313
- package/dist/node_modules/detect-libc/lib/elf.js +1 -39
- package/dist/node_modules/detect-libc/lib/filesystem.js +1 -51
- package/dist/node_modules/detect-libc/lib/process.js +1 -24
- package/dist/node_modules/detect-libc/package.json +1 -40
- package/dist/node_modules/estree-walker/dist/umd/estree-walker.js +1 -344
- package/dist/node_modules/estree-walker/package.json +1 -28
- package/dist/node_modules/file-uri-to-path/index.js +1 -66
- package/dist/node_modules/file-uri-to-path/package.json +1 -28
- package/dist/node_modules/glob/dist/commonjs/glob.js +1 -247
- package/dist/node_modules/glob/dist/commonjs/has-magic.js +1 -27
- package/dist/node_modules/glob/dist/commonjs/ignore.js +1 -119
- package/dist/node_modules/glob/dist/commonjs/index.js +1 -68
- package/dist/node_modules/glob/dist/commonjs/pattern.js +1 -219
- package/dist/node_modules/glob/dist/commonjs/processor.js +1 -301
- package/dist/node_modules/glob/dist/commonjs/walker.js +1 -387
- package/dist/node_modules/glob/package.json +1 -81
- package/dist/node_modules/graceful-fs/clone.js +1 -23
- package/dist/node_modules/graceful-fs/graceful-fs.js +2 -448
- package/dist/node_modules/graceful-fs/legacy-streams.js +1 -118
- package/dist/node_modules/graceful-fs/package.json +1 -49
- package/dist/node_modules/graceful-fs/polyfills.js +1 -355
- package/dist/node_modules/lru-cache/dist/commonjs/index.js +1 -1546
- package/dist/node_modules/lru-cache/package.json +1 -89
- package/dist/node_modules/minimatch/dist/commonjs/assert-valid-pattern.js +1 -14
- package/dist/node_modules/minimatch/dist/commonjs/ast.js +1 -592
- package/dist/node_modules/minimatch/dist/commonjs/brace-expressions.js +1 -152
- package/dist/node_modules/minimatch/dist/commonjs/escape.js +1 -22
- package/dist/node_modules/minimatch/dist/commonjs/index.js +3 -1017
- package/dist/node_modules/minimatch/dist/commonjs/unescape.js +1 -24
- package/dist/node_modules/minimatch/package.json +0 -63
- package/dist/node_modules/minipass/dist/commonjs/index.js +1 -1028
- package/dist/node_modules/minipass/package.json +0 -63
- package/dist/node_modules/node-gyp-build/index.js +1 -6
- package/dist/node_modules/node-gyp-build/node-gyp-build.js +3 -207
- package/dist/node_modules/node-gyp-build/package.json +1 -25
- package/dist/node_modules/nopt/lib/debug.js +1 -5
- package/dist/node_modules/nopt/lib/nopt-lib.js +1 -514
- package/dist/node_modules/nopt/lib/nopt.js +1 -34
- package/dist/node_modules/nopt/lib/type-defs.js +1 -91
- package/dist/node_modules/nopt/package.json +1 -48
- package/dist/node_modules/path-scurry/dist/commonjs/index.js +1 -2014
- package/dist/node_modules/path-scurry/package.json +1 -71
- package/dist/node_modules/picomatch/index.js +1 -17
- package/dist/node_modules/picomatch/lib/constants.js +1 -180
- package/dist/node_modules/picomatch/lib/parse.js +1 -1085
- package/dist/node_modules/picomatch/lib/picomatch.js +1 -341
- package/dist/node_modules/picomatch/lib/scan.js +1 -391
- package/dist/node_modules/picomatch/lib/utils.js +1 -72
- package/dist/node_modules/picomatch/package.json +1 -79
- package/dist/node_modules/resolve-from/index.js +1 -47
- package/dist/node_modules/resolve-from/package.json +1 -33
- package/dist/node_modules/semver/classes/comparator.js +1 -143
- package/dist/node_modules/semver/classes/range.js +1 -557
- package/dist/node_modules/semver/classes/semver.js +1 -333
- package/dist/node_modules/semver/functions/clean.js +1 -8
- package/dist/node_modules/semver/functions/cmp.js +1 -54
- package/dist/node_modules/semver/functions/coerce.js +1 -62
- package/dist/node_modules/semver/functions/compare-build.js +1 -9
- package/dist/node_modules/semver/functions/compare-loose.js +1 -5
- package/dist/node_modules/semver/functions/compare.js +1 -7
- package/dist/node_modules/semver/functions/diff.js +1 -60
- package/dist/node_modules/semver/functions/eq.js +1 -5
- package/dist/node_modules/semver/functions/gt.js +1 -5
- package/dist/node_modules/semver/functions/gte.js +1 -5
- package/dist/node_modules/semver/functions/inc.js +1 -21
- package/dist/node_modules/semver/functions/lt.js +1 -5
- package/dist/node_modules/semver/functions/lte.js +1 -5
- package/dist/node_modules/semver/functions/major.js +1 -5
- package/dist/node_modules/semver/functions/minor.js +1 -5
- package/dist/node_modules/semver/functions/neq.js +1 -5
- package/dist/node_modules/semver/functions/parse.js +1 -18
- package/dist/node_modules/semver/functions/patch.js +1 -5
- package/dist/node_modules/semver/functions/prerelease.js +1 -8
- package/dist/node_modules/semver/functions/rcompare.js +1 -5
- package/dist/node_modules/semver/functions/rsort.js +1 -5
- package/dist/node_modules/semver/functions/satisfies.js +1 -12
- package/dist/node_modules/semver/functions/sort.js +1 -5
- package/dist/node_modules/semver/functions/valid.js +1 -8
- package/dist/node_modules/semver/index.js +1 -91
- package/dist/node_modules/semver/internal/constants.js +1 -37
- package/dist/node_modules/semver/internal/debug.js +1 -11
- package/dist/node_modules/semver/internal/identifiers.js +1 -29
- package/dist/node_modules/semver/internal/lrucache.js +1 -42
- package/dist/node_modules/semver/internal/parse-options.js +1 -17
- package/dist/node_modules/semver/internal/re.js +1 -223
- package/dist/node_modules/semver/package.json +1 -74
- package/dist/node_modules/semver/preload.js +1 -4
- package/dist/node_modules/semver/ranges/gtr.js +1 -6
- package/dist/node_modules/semver/ranges/intersects.js +1 -9
- package/dist/node_modules/semver/ranges/ltr.js +1 -6
- package/dist/node_modules/semver/ranges/max-satisfying.js +1 -27
- package/dist/node_modules/semver/ranges/min-satisfying.js +1 -26
- package/dist/node_modules/semver/ranges/min-version.js +1 -63
- package/dist/node_modules/semver/ranges/outside.js +1 -82
- package/dist/node_modules/semver/ranges/simplify.js +1 -49
- package/dist/node_modules/semver/ranges/subset.js +1 -249
- package/dist/node_modules/semver/ranges/to-comparators.js +1 -10
- package/dist/node_modules/semver/ranges/valid.js +1 -13
- package/package.json +11 -10
- package/dist/node_modules/.nft/confbox@0.1.8/dist/index.cjs +0 -1
- package/dist/node_modules/.nft/confbox@0.1.8/dist/index.mjs +0 -1
- package/dist/node_modules/.nft/confbox@0.1.8/dist/json5.cjs +0 -14
- package/dist/node_modules/.nft/confbox@0.1.8/dist/json5.mjs +0 -14
- package/dist/node_modules/.nft/confbox@0.1.8/dist/shared/confbox.3768c7e9.cjs +0 -1
- package/dist/node_modules/.nft/confbox@0.1.8/dist/shared/confbox.6b479c78.cjs +0 -7
- package/dist/node_modules/.nft/confbox@0.1.8/dist/shared/confbox.9388d834.mjs +0 -1
- package/dist/node_modules/.nft/confbox@0.1.8/dist/shared/confbox.f9f03f05.mjs +0 -7
- package/dist/node_modules/.nft/confbox@0.1.8/dist/toml.cjs +0 -239
- package/dist/node_modules/.nft/confbox@0.1.8/dist/toml.mjs +0 -239
- package/dist/node_modules/.nft/confbox@0.1.8/dist/yaml.cjs +0 -32
- package/dist/node_modules/.nft/confbox@0.1.8/dist/yaml.mjs +0 -32
- package/dist/node_modules/.nft/confbox@0.1.8/package.json +0 -86
- package/dist/node_modules/.nft/confbox@0.2.2/dist/index.mjs +0 -1
- package/dist/node_modules/.nft/confbox@0.2.2/dist/ini.mjs +0 -3
- package/dist/node_modules/.nft/confbox@0.2.2/dist/json5.mjs +0 -14
- package/dist/node_modules/.nft/confbox@0.2.2/dist/shared/confbox.DA7CpUDY.mjs +0 -1
- package/dist/node_modules/.nft/confbox@0.2.2/dist/shared/confbox.DnMsyigM.mjs +0 -7
- package/dist/node_modules/.nft/confbox@0.2.2/dist/toml.mjs +0 -239
- package/dist/node_modules/.nft/confbox@0.2.2/dist/yaml.mjs +0 -32
- package/dist/node_modules/.nft/confbox@0.2.2/package.json +0 -85
- package/dist/node_modules/.nft/pkg-types@1.3.1/dist/index.cjs +0 -171
- package/dist/node_modules/.nft/pkg-types@1.3.1/dist/index.mjs +0 -157
- package/dist/node_modules/.nft/pkg-types@1.3.1/package.json +0 -47
- package/dist/node_modules/.nft/pkg-types@2.3.0/dist/index.mjs +0 -371
- package/dist/node_modules/.nft/pkg-types@2.3.0/package.json +0 -45
- package/dist/node_modules/agent-base/dist/helpers.js +0 -66
- package/dist/node_modules/agent-base/dist/index.js +0 -178
- package/dist/node_modules/agent-base/package.json +0 -46
- package/dist/node_modules/chownr/dist/commonjs/index.js +0 -93
- package/dist/node_modules/chownr/dist/commonjs/package.json +0 -3
- package/dist/node_modules/chownr/package.json +0 -69
- package/dist/node_modules/debug/package.json +0 -64
- package/dist/node_modules/debug/src/browser.js +0 -272
- package/dist/node_modules/debug/src/common.js +0 -292
- package/dist/node_modules/debug/src/index.js +0 -10
- package/dist/node_modules/debug/src/node.js +0 -263
- package/dist/node_modules/exsolve/dist/index.mjs +0 -1440
- package/dist/node_modules/exsolve/package.json +0 -43
- package/dist/node_modules/fsevents/fsevents.js +0 -83
- package/dist/node_modules/fsevents/fsevents.node +0 -0
- package/dist/node_modules/fsevents/package.json +0 -62
- package/dist/node_modules/has-flag/index.js +0 -8
- package/dist/node_modules/has-flag/package.json +0 -46
- package/dist/node_modules/https-proxy-agent/dist/index.js +0 -180
- package/dist/node_modules/https-proxy-agent/dist/parse-proxy-response.js +0 -101
- package/dist/node_modules/https-proxy-agent/package.json +0 -50
- package/dist/node_modules/minizlib/dist/commonjs/constants.js +0 -123
- package/dist/node_modules/minizlib/dist/commonjs/index.js +0 -416
- package/dist/node_modules/minizlib/dist/commonjs/package.json +0 -3
- package/dist/node_modules/minizlib/package.json +0 -80
- package/dist/node_modules/mlly/dist/index.cjs +0 -2661
- package/dist/node_modules/mlly/dist/index.mjs +0 -2613
- package/dist/node_modules/mlly/package.json +0 -55
- package/dist/node_modules/ms/index.js +0 -162
- package/dist/node_modules/ms/package.json +0 -38
- package/dist/node_modules/node-fetch/lib/index.js +0 -1787
- package/dist/node_modules/node-fetch/package.json +0 -89
- package/dist/node_modules/pathe/dist/index.cjs +0 -39
- package/dist/node_modules/pathe/dist/index.mjs +0 -19
- package/dist/node_modules/pathe/dist/shared/pathe.BSlhyZSM.cjs +0 -266
- package/dist/node_modules/pathe/dist/shared/pathe.M-eThtNZ.mjs +0 -249
- package/dist/node_modules/pathe/package.json +0 -61
- package/dist/node_modules/rollup/dist/es/package.json +0 -1
- package/dist/node_modules/rollup/dist/es/rollup.js +0 -17
- package/dist/node_modules/rollup/dist/es/shared/node-entry.js +0 -23920
- package/dist/node_modules/rollup/dist/es/shared/parseAst.js +0 -2086
- package/dist/node_modules/rollup/dist/es/shared/watch.js +0 -9297
- package/dist/node_modules/rollup/dist/native.js +0 -129
- package/dist/node_modules/rollup/package.json +0 -273
- package/dist/node_modules/supports-color/index.js +0 -135
- package/dist/node_modules/supports-color/package.json +0 -53
- package/dist/node_modules/tar/dist/commonjs/create.js +0 -83
- package/dist/node_modules/tar/dist/commonjs/cwd-error.js +0 -18
- package/dist/node_modules/tar/dist/commonjs/extract.js +0 -78
- package/dist/node_modules/tar/dist/commonjs/get-write-flag.js +0 -29
- package/dist/node_modules/tar/dist/commonjs/header.js +0 -306
- package/dist/node_modules/tar/dist/commonjs/index.js +0 -54
- package/dist/node_modules/tar/dist/commonjs/large-numbers.js +0 -99
- package/dist/node_modules/tar/dist/commonjs/list.js +0 -138
- package/dist/node_modules/tar/dist/commonjs/make-command.js +0 -61
- package/dist/node_modules/tar/dist/commonjs/mkdir.js +0 -188
- package/dist/node_modules/tar/dist/commonjs/mode-fix.js +0 -29
- package/dist/node_modules/tar/dist/commonjs/normalize-unicode.js +0 -34
- package/dist/node_modules/tar/dist/commonjs/normalize-windows-path.js +0 -12
- package/dist/node_modules/tar/dist/commonjs/options.js +0 -66
- package/dist/node_modules/tar/dist/commonjs/pack.js +0 -491
- package/dist/node_modules/tar/dist/commonjs/package.json +0 -3
- package/dist/node_modules/tar/dist/commonjs/parse.js +0 -622
- package/dist/node_modules/tar/dist/commonjs/path-reservations.js +0 -170
- package/dist/node_modules/tar/dist/commonjs/pax.js +0 -158
- package/dist/node_modules/tar/dist/commonjs/read-entry.js +0 -140
- package/dist/node_modules/tar/dist/commonjs/replace.js +0 -232
- package/dist/node_modules/tar/dist/commonjs/strip-absolute-path.js +0 -29
- package/dist/node_modules/tar/dist/commonjs/strip-trailing-slashes.js +0 -18
- package/dist/node_modules/tar/dist/commonjs/symlink-error.js +0 -19
- package/dist/node_modules/tar/dist/commonjs/types.js +0 -50
- package/dist/node_modules/tar/dist/commonjs/unpack.js +0 -871
- package/dist/node_modules/tar/dist/commonjs/update.js +0 -33
- package/dist/node_modules/tar/dist/commonjs/warn-method.js +0 -31
- package/dist/node_modules/tar/dist/commonjs/winchars.js +0 -14
- package/dist/node_modules/tar/dist/commonjs/write-entry.js +0 -689
- package/dist/node_modules/tar/package.json +0 -326
- package/dist/node_modules/tr46/index.js +0 -193
- package/dist/node_modules/tr46/lib/mappingTable.json +0 -1
- package/dist/node_modules/tr46/package.json +0 -31
- package/dist/node_modules/ufo/dist/index.cjs +0 -691
- package/dist/node_modules/ufo/dist/index.mjs +0 -638
- package/dist/node_modules/ufo/package.json +0 -47
- package/dist/node_modules/webidl-conversions/lib/index.js +0 -189
- package/dist/node_modules/webidl-conversions/package.json +0 -23
- package/dist/node_modules/whatwg-url/lib/URL-impl.js +0 -200
- package/dist/node_modules/whatwg-url/lib/URL.js +0 -196
- package/dist/node_modules/whatwg-url/lib/public-api.js +0 -11
- package/dist/node_modules/whatwg-url/lib/url-state-machine.js +0 -1297
- package/dist/node_modules/whatwg-url/lib/utils.js +0 -20
- package/dist/node_modules/whatwg-url/package.json +0 -32
- package/dist/node_modules/yallist/dist/commonjs/index.js +0 -384
- package/dist/node_modules/yallist/dist/commonjs/package.json +0 -3
- package/dist/node_modules/yallist/package.json +0 -68
package/README.md
CHANGED
|
@@ -39,6 +39,7 @@ export default {
|
|
|
39
39
|
// moduleDirectories: ["node_modules"],
|
|
40
40
|
// traceInclude: ["some-lib"],
|
|
41
41
|
// writePackageJson: true,
|
|
42
|
+
// hooks: {},
|
|
42
43
|
// traceOptions: { /* see https://github.com/vercel/nft#options */ }
|
|
43
44
|
}),
|
|
44
45
|
],
|
|
@@ -55,6 +56,44 @@ await traceNodeModules(["./index.mjs"], {
|
|
|
55
56
|
});
|
|
56
57
|
```
|
|
57
58
|
|
|
59
|
+
### Hooks
|
|
60
|
+
|
|
61
|
+
After the Rollup plugin traces the required files, `traceNodeModules` processes them into an optimized `node_modules` output.
|
|
62
|
+
|
|
63
|
+
Each phase can be extended through hooks:
|
|
64
|
+
|
|
65
|
+
```js
|
|
66
|
+
rollupNodeFileTrace({
|
|
67
|
+
hooks: {
|
|
68
|
+
traceStart: (files) => {},
|
|
69
|
+
traceResult: (result) => {},
|
|
70
|
+
tracedFiles: (files) => {},
|
|
71
|
+
tracedPackages: (packages) => {},
|
|
72
|
+
},
|
|
73
|
+
});
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
### Transforming
|
|
77
|
+
|
|
78
|
+
Before writing files, you can transform some of them.
|
|
79
|
+
|
|
80
|
+
**Example:**
|
|
81
|
+
|
|
82
|
+
```js
|
|
83
|
+
import { minify } from "oxc-minify";
|
|
84
|
+
|
|
85
|
+
rollupNodeFileTrace({
|
|
86
|
+
transform: [
|
|
87
|
+
{
|
|
88
|
+
filter: (id) => /\.m?js$/.test(id),
|
|
89
|
+
handler: (code, id) => {
|
|
90
|
+
return minify(id, code).code;
|
|
91
|
+
},
|
|
92
|
+
},
|
|
93
|
+
],
|
|
94
|
+
});
|
|
95
|
+
```
|
|
96
|
+
|
|
58
97
|
## Development
|
|
59
98
|
|
|
60
99
|
<details>
|
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { NodeFileTraceOptions } from "@vercel/nft";
|
|
1
|
+
import { NodeFileTraceOptions, NodeFileTraceResult } from "@vercel/nft";
|
|
2
2
|
import { Plugin } from "rollup";
|
|
3
|
+
import { PackageJson } from "pkg-types";
|
|
3
4
|
|
|
4
5
|
//#region src/types.d.ts
|
|
5
6
|
interface ExternalsTraceOptions {
|
|
@@ -35,7 +36,17 @@ interface ExternalsTraceOptions {
|
|
|
35
36
|
* If `true`, writes a `package.json` file to the output directory (parent) with the traced files as dependencies.
|
|
36
37
|
*/
|
|
37
38
|
writePackageJson?: boolean;
|
|
39
|
+
/**
|
|
40
|
+
* Hook functions for allow extending tracing behavior.
|
|
41
|
+
*/
|
|
42
|
+
hooks?: TraceHooks;
|
|
43
|
+
/** Transform traced files */
|
|
44
|
+
transform?: Transformer[];
|
|
38
45
|
}
|
|
46
|
+
type Transformer = {
|
|
47
|
+
filter: (id: string) => boolean;
|
|
48
|
+
handler: (code: string, id: string) => string | Promise<string>;
|
|
49
|
+
};
|
|
39
50
|
interface ExternalsPluginOptions extends ExternalsTraceOptions {
|
|
40
51
|
/**
|
|
41
52
|
* If `true`, disables automatic tracing of `node_modules` dependencies and keeps them as absolute external paths.
|
|
@@ -58,6 +69,28 @@ interface ExternalsPluginOptions extends ExternalsTraceOptions {
|
|
|
58
69
|
*/
|
|
59
70
|
traceInclude?: string[];
|
|
60
71
|
}
|
|
72
|
+
type TracedFile = {
|
|
73
|
+
path: string;
|
|
74
|
+
subpath: string;
|
|
75
|
+
parents: string[];
|
|
76
|
+
pkgPath: string;
|
|
77
|
+
pkgName: string;
|
|
78
|
+
pkgVersion: string;
|
|
79
|
+
};
|
|
80
|
+
type TracedPackage = {
|
|
81
|
+
name: string;
|
|
82
|
+
versions: Record<string, {
|
|
83
|
+
pkgJSON: PackageJson;
|
|
84
|
+
path: string;
|
|
85
|
+
files: string[];
|
|
86
|
+
}>;
|
|
87
|
+
};
|
|
88
|
+
interface TraceHooks {
|
|
89
|
+
traceStart: (files: string[]) => Promise<void>;
|
|
90
|
+
traceResult: (result: NodeFileTraceResult) => Promise<void>;
|
|
91
|
+
tracedFiles: (files: Record<string, TracedFile>) => Promise<void>;
|
|
92
|
+
tracedPackages: (packages: Record<string, TracedPackage>) => Promise<void>;
|
|
93
|
+
}
|
|
61
94
|
//#endregion
|
|
62
95
|
//#region src/plugin.d.ts
|
|
63
96
|
declare function rollupNodeFileTrace(opts?: ExternalsPluginOptions): Plugin;
|
package/dist/index.mjs
CHANGED
|
@@ -1111,6 +1111,18 @@ const dirname = function(p) {
|
|
|
1111
1111
|
if (segments.length === 1 && _DRIVE_LETTER_RE.test(segments[0])) segments[0] += "/";
|
|
1112
1112
|
return segments.join("/") || (isAbsolute$1(p) ? "/" : ".");
|
|
1113
1113
|
};
|
|
1114
|
+
const basename = function(p, extension) {
|
|
1115
|
+
const segments = normalizeWindowsPath(p).split("/");
|
|
1116
|
+
let lastSegment = "";
|
|
1117
|
+
for (let i = segments.length - 1; i >= 0; i--) {
|
|
1118
|
+
const val = segments[i];
|
|
1119
|
+
if (val) {
|
|
1120
|
+
lastSegment = val;
|
|
1121
|
+
break;
|
|
1122
|
+
}
|
|
1123
|
+
}
|
|
1124
|
+
return extension && lastSegment.endsWith(extension) ? lastSegment.slice(0, -extension.length) : lastSegment;
|
|
1125
|
+
};
|
|
1114
1126
|
|
|
1115
1127
|
//#endregion
|
|
1116
1128
|
//#region node_modules/.pnpm/ufo@1.6.1/node_modules/ufo/dist/index.mjs
|
|
@@ -4878,7 +4890,8 @@ var require_semver = /* @__PURE__ */ __commonJS({ "node_modules/.pnpm/semver@7.7
|
|
|
4878
4890
|
//#region src/trace.ts
|
|
4879
4891
|
var import_semver = /* @__PURE__ */ __toESM(require_semver(), 1);
|
|
4880
4892
|
async function traceNodeModules(input, opts) {
|
|
4881
|
-
|
|
4893
|
+
await opts?.hooks?.traceStart?.(input);
|
|
4894
|
+
const traceResult = await nodeFileTrace([...input], {
|
|
4882
4895
|
conditions: (opts.exportConditions || [
|
|
4883
4896
|
"node",
|
|
4884
4897
|
"import",
|
|
@@ -4890,8 +4903,9 @@ async function traceNodeModules(input, opts) {
|
|
|
4890
4903
|
].includes(c)),
|
|
4891
4904
|
...opts.traceOptions
|
|
4892
4905
|
});
|
|
4906
|
+
await opts?.hooks?.traceResult?.(traceResult);
|
|
4893
4907
|
const _resolveTracedPath = (p) => promises.realpath(resolve(opts.traceOptions?.base || ".", p));
|
|
4894
|
-
const tracedFiles = Object.fromEntries(await Promise.all([...
|
|
4908
|
+
const tracedFiles = Object.fromEntries(await Promise.all([...traceResult.reasons.entries()].map(async ([_path, reasons]) => {
|
|
4895
4909
|
if (reasons.ignored) return;
|
|
4896
4910
|
const path$1 = await _resolveTracedPath(_path);
|
|
4897
4911
|
if (!path$1.includes("node_modules")) return;
|
|
@@ -4907,6 +4921,7 @@ async function traceNodeModules(input, opts) {
|
|
|
4907
4921
|
pkgPath
|
|
4908
4922
|
}];
|
|
4909
4923
|
})).then((r$3) => r$3.filter(Boolean)));
|
|
4924
|
+
await opts?.hooks?.tracedFiles?.(tracedFiles);
|
|
4910
4925
|
const tracedPackages = {};
|
|
4911
4926
|
for (const tracedFile of Object.values(tracedFiles)) {
|
|
4912
4927
|
const pkgName = tracedFile.pkgName;
|
|
@@ -4936,6 +4951,7 @@ async function traceNodeModules(input, opts) {
|
|
|
4936
4951
|
tracedFile.pkgName = pkgName;
|
|
4937
4952
|
if (pkgJSON.version) tracedFile.pkgVersion = pkgJSON.version;
|
|
4938
4953
|
}
|
|
4954
|
+
await opts?.hooks?.tracedPackages?.(tracedPackages);
|
|
4939
4955
|
const usedAliases = {};
|
|
4940
4956
|
const outDir = resolve(opts.rootDir || ".", opts.outDir || "dist", "node_modules");
|
|
4941
4957
|
const writePackage = async (name, version, _pkgPath) => {
|
|
@@ -4946,7 +4962,12 @@ async function traceNodeModules(input, opts) {
|
|
|
4946
4962
|
if (!subpath) continue;
|
|
4947
4963
|
const dst = resolve(outDir, pkgPath, subpath);
|
|
4948
4964
|
await promises.mkdir(dirname(dst), { recursive: true });
|
|
4949
|
-
|
|
4965
|
+
const transformers = (opts.transform || []).filter((t$5) => t$5?.filter?.(src$1) && t$5.handler);
|
|
4966
|
+
if (transformers.length > 0) {
|
|
4967
|
+
let content = await promises.readFile(src$1, "utf8");
|
|
4968
|
+
for (const transformer of transformers) content = await transformer.handler(content, src$1) ?? content;
|
|
4969
|
+
await promises.writeFile(dst, content, "utf8");
|
|
4970
|
+
} else await promises.copyFile(src$1, dst);
|
|
4950
4971
|
if (opts.chmod) await promises.chmod(dst, opts.chmod === true ? 420 : opts.chmod);
|
|
4951
4972
|
}
|
|
4952
4973
|
const pkgJSON = pkg.versions[version].pkgJSON;
|
|
@@ -5000,11 +5021,11 @@ async function traceNodeModules(input, opts) {
|
|
|
5000
5021
|
return compareVersions(v1, v2);
|
|
5001
5022
|
});
|
|
5002
5023
|
for (const [version, parentPkgs] of versionEntries) {
|
|
5003
|
-
await writePackage(pkgName, version, `.
|
|
5004
|
-
await linkPackage(`.
|
|
5024
|
+
await writePackage(pkgName, version, `.nf3/${pkgName}@${version}`);
|
|
5025
|
+
await linkPackage(`.nf3/${pkgName}@${version}`, `${pkgName}`);
|
|
5005
5026
|
for (const parentPkg of parentPkgs) {
|
|
5006
5027
|
const parentPkgName = parentPkg.replace(/@[^@]+$/, "");
|
|
5007
|
-
await (multiVersionPkgs[parentPkgName] ? linkPackage(`.
|
|
5028
|
+
await (multiVersionPkgs[parentPkgName] ? linkPackage(`.nf3/${pkgName}@${version}`, `.nf3/${parentPkg}/node_modules/${pkgName}`) : linkPackage(`.nf3/${pkgName}@${version}`, `${parentPkgName}/node_modules/${pkgName}`));
|
|
5008
5029
|
}
|
|
5009
5030
|
}
|
|
5010
5031
|
}
|
|
@@ -5070,6 +5091,7 @@ function rollupNodeFileTrace(opts = {}) {
|
|
|
5070
5091
|
const externalMatch = externalMatchers.find((m$2) => m$2(id, importer));
|
|
5071
5092
|
if (inlineMatch && (!externalMatch || externalMatch && (inlineMatch.score || 0) > (externalMatch.score || 0))) return true;
|
|
5072
5093
|
};
|
|
5094
|
+
const JS_SOURCE_RE = /(?<!\.d)\.[mc]?[jt]s$/;
|
|
5073
5095
|
return {
|
|
5074
5096
|
name: "nf3",
|
|
5075
5097
|
resolveId: {
|
|
@@ -5077,6 +5099,8 @@ function rollupNodeFileTrace(opts = {}) {
|
|
|
5077
5099
|
async handler(originalId, importer, options) {
|
|
5078
5100
|
if (!originalId || originalId.startsWith("\0") || originalId.includes("?") || originalId.startsWith("#")) return null;
|
|
5079
5101
|
if (originalId.startsWith(".")) return null;
|
|
5102
|
+
if (/^[a-z0-9]{2,}:/i.test(originalId)) return null;
|
|
5103
|
+
if (importer && !JS_SOURCE_RE.test(basename(importer))) return null;
|
|
5080
5104
|
const id = normalize(originalId);
|
|
5081
5105
|
if (isExplicitInline(id, importer)) return null;
|
|
5082
5106
|
const resolved = await this.resolve(originalId, importer, options) || { id };
|
|
@@ -5121,13 +5145,16 @@ function rollupNodeFileTrace(opts = {}) {
|
|
|
5121
5145
|
};
|
|
5122
5146
|
}
|
|
5123
5147
|
},
|
|
5124
|
-
|
|
5125
|
-
|
|
5126
|
-
|
|
5127
|
-
|
|
5128
|
-
|
|
5148
|
+
buildEnd: {
|
|
5149
|
+
order: "post",
|
|
5150
|
+
async handler() {
|
|
5151
|
+
if (opts.noTrace) return;
|
|
5152
|
+
for (const pkgName of opts.traceInclude || []) {
|
|
5153
|
+
const path$1 = await this.resolve(pkgName);
|
|
5154
|
+
if (path$1?.id) trackedExternals.add(path$1.id.replace(/\?.+/, ""));
|
|
5155
|
+
}
|
|
5156
|
+
await traceNodeModules([...trackedExternals], opts);
|
|
5129
5157
|
}
|
|
5130
|
-
await traceNodeModules([...trackedExternals], opts);
|
|
5131
5158
|
}
|
|
5132
5159
|
};
|
|
5133
5160
|
}
|
|
@@ -1,430 +1 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.WriteStreamSync = exports.WriteStream = exports.ReadStreamSync = exports.ReadStream = void 0;
|
|
7
|
-
const events_1 = __importDefault(require("events"));
|
|
8
|
-
const fs_1 = __importDefault(require("fs"));
|
|
9
|
-
const minipass_1 = require("minipass");
|
|
10
|
-
const writev = fs_1.default.writev;
|
|
11
|
-
const _autoClose = Symbol('_autoClose');
|
|
12
|
-
const _close = Symbol('_close');
|
|
13
|
-
const _ended = Symbol('_ended');
|
|
14
|
-
const _fd = Symbol('_fd');
|
|
15
|
-
const _finished = Symbol('_finished');
|
|
16
|
-
const _flags = Symbol('_flags');
|
|
17
|
-
const _flush = Symbol('_flush');
|
|
18
|
-
const _handleChunk = Symbol('_handleChunk');
|
|
19
|
-
const _makeBuf = Symbol('_makeBuf');
|
|
20
|
-
const _mode = Symbol('_mode');
|
|
21
|
-
const _needDrain = Symbol('_needDrain');
|
|
22
|
-
const _onerror = Symbol('_onerror');
|
|
23
|
-
const _onopen = Symbol('_onopen');
|
|
24
|
-
const _onread = Symbol('_onread');
|
|
25
|
-
const _onwrite = Symbol('_onwrite');
|
|
26
|
-
const _open = Symbol('_open');
|
|
27
|
-
const _path = Symbol('_path');
|
|
28
|
-
const _pos = Symbol('_pos');
|
|
29
|
-
const _queue = Symbol('_queue');
|
|
30
|
-
const _read = Symbol('_read');
|
|
31
|
-
const _readSize = Symbol('_readSize');
|
|
32
|
-
const _reading = Symbol('_reading');
|
|
33
|
-
const _remain = Symbol('_remain');
|
|
34
|
-
const _size = Symbol('_size');
|
|
35
|
-
const _write = Symbol('_write');
|
|
36
|
-
const _writing = Symbol('_writing');
|
|
37
|
-
const _defaultFlag = Symbol('_defaultFlag');
|
|
38
|
-
const _errored = Symbol('_errored');
|
|
39
|
-
class ReadStream extends minipass_1.Minipass {
|
|
40
|
-
[_errored] = false;
|
|
41
|
-
[_fd];
|
|
42
|
-
[_path];
|
|
43
|
-
[_readSize];
|
|
44
|
-
[_reading] = false;
|
|
45
|
-
[_size];
|
|
46
|
-
[_remain];
|
|
47
|
-
[_autoClose];
|
|
48
|
-
constructor(path, opt) {
|
|
49
|
-
opt = opt || {};
|
|
50
|
-
super(opt);
|
|
51
|
-
this.readable = true;
|
|
52
|
-
this.writable = false;
|
|
53
|
-
if (typeof path !== 'string') {
|
|
54
|
-
throw new TypeError('path must be a string');
|
|
55
|
-
}
|
|
56
|
-
this[_errored] = false;
|
|
57
|
-
this[_fd] = typeof opt.fd === 'number' ? opt.fd : undefined;
|
|
58
|
-
this[_path] = path;
|
|
59
|
-
this[_readSize] = opt.readSize || 16 * 1024 * 1024;
|
|
60
|
-
this[_reading] = false;
|
|
61
|
-
this[_size] = typeof opt.size === 'number' ? opt.size : Infinity;
|
|
62
|
-
this[_remain] = this[_size];
|
|
63
|
-
this[_autoClose] =
|
|
64
|
-
typeof opt.autoClose === 'boolean' ? opt.autoClose : true;
|
|
65
|
-
if (typeof this[_fd] === 'number') {
|
|
66
|
-
this[_read]();
|
|
67
|
-
}
|
|
68
|
-
else {
|
|
69
|
-
this[_open]();
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
get fd() {
|
|
73
|
-
return this[_fd];
|
|
74
|
-
}
|
|
75
|
-
get path() {
|
|
76
|
-
return this[_path];
|
|
77
|
-
}
|
|
78
|
-
//@ts-ignore
|
|
79
|
-
write() {
|
|
80
|
-
throw new TypeError('this is a readable stream');
|
|
81
|
-
}
|
|
82
|
-
//@ts-ignore
|
|
83
|
-
end() {
|
|
84
|
-
throw new TypeError('this is a readable stream');
|
|
85
|
-
}
|
|
86
|
-
[_open]() {
|
|
87
|
-
fs_1.default.open(this[_path], 'r', (er, fd) => this[_onopen](er, fd));
|
|
88
|
-
}
|
|
89
|
-
[_onopen](er, fd) {
|
|
90
|
-
if (er) {
|
|
91
|
-
this[_onerror](er);
|
|
92
|
-
}
|
|
93
|
-
else {
|
|
94
|
-
this[_fd] = fd;
|
|
95
|
-
this.emit('open', fd);
|
|
96
|
-
this[_read]();
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
[_makeBuf]() {
|
|
100
|
-
return Buffer.allocUnsafe(Math.min(this[_readSize], this[_remain]));
|
|
101
|
-
}
|
|
102
|
-
[_read]() {
|
|
103
|
-
if (!this[_reading]) {
|
|
104
|
-
this[_reading] = true;
|
|
105
|
-
const buf = this[_makeBuf]();
|
|
106
|
-
/* c8 ignore start */
|
|
107
|
-
if (buf.length === 0) {
|
|
108
|
-
return process.nextTick(() => this[_onread](null, 0, buf));
|
|
109
|
-
}
|
|
110
|
-
/* c8 ignore stop */
|
|
111
|
-
fs_1.default.read(this[_fd], buf, 0, buf.length, null, (er, br, b) => this[_onread](er, br, b));
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
[_onread](er, br, buf) {
|
|
115
|
-
this[_reading] = false;
|
|
116
|
-
if (er) {
|
|
117
|
-
this[_onerror](er);
|
|
118
|
-
}
|
|
119
|
-
else if (this[_handleChunk](br, buf)) {
|
|
120
|
-
this[_read]();
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
[_close]() {
|
|
124
|
-
if (this[_autoClose] && typeof this[_fd] === 'number') {
|
|
125
|
-
const fd = this[_fd];
|
|
126
|
-
this[_fd] = undefined;
|
|
127
|
-
fs_1.default.close(fd, er => er ? this.emit('error', er) : this.emit('close'));
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
[_onerror](er) {
|
|
131
|
-
this[_reading] = true;
|
|
132
|
-
this[_close]();
|
|
133
|
-
this.emit('error', er);
|
|
134
|
-
}
|
|
135
|
-
[_handleChunk](br, buf) {
|
|
136
|
-
let ret = false;
|
|
137
|
-
// no effect if infinite
|
|
138
|
-
this[_remain] -= br;
|
|
139
|
-
if (br > 0) {
|
|
140
|
-
ret = super.write(br < buf.length ? buf.subarray(0, br) : buf);
|
|
141
|
-
}
|
|
142
|
-
if (br === 0 || this[_remain] <= 0) {
|
|
143
|
-
ret = false;
|
|
144
|
-
this[_close]();
|
|
145
|
-
super.end();
|
|
146
|
-
}
|
|
147
|
-
return ret;
|
|
148
|
-
}
|
|
149
|
-
emit(ev, ...args) {
|
|
150
|
-
switch (ev) {
|
|
151
|
-
case 'prefinish':
|
|
152
|
-
case 'finish':
|
|
153
|
-
return false;
|
|
154
|
-
case 'drain':
|
|
155
|
-
if (typeof this[_fd] === 'number') {
|
|
156
|
-
this[_read]();
|
|
157
|
-
}
|
|
158
|
-
return false;
|
|
159
|
-
case 'error':
|
|
160
|
-
if (this[_errored]) {
|
|
161
|
-
return false;
|
|
162
|
-
}
|
|
163
|
-
this[_errored] = true;
|
|
164
|
-
return super.emit(ev, ...args);
|
|
165
|
-
default:
|
|
166
|
-
return super.emit(ev, ...args);
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
exports.ReadStream = ReadStream;
|
|
171
|
-
class ReadStreamSync extends ReadStream {
|
|
172
|
-
[_open]() {
|
|
173
|
-
let threw = true;
|
|
174
|
-
try {
|
|
175
|
-
this[_onopen](null, fs_1.default.openSync(this[_path], 'r'));
|
|
176
|
-
threw = false;
|
|
177
|
-
}
|
|
178
|
-
finally {
|
|
179
|
-
if (threw) {
|
|
180
|
-
this[_close]();
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
[_read]() {
|
|
185
|
-
let threw = true;
|
|
186
|
-
try {
|
|
187
|
-
if (!this[_reading]) {
|
|
188
|
-
this[_reading] = true;
|
|
189
|
-
do {
|
|
190
|
-
const buf = this[_makeBuf]();
|
|
191
|
-
/* c8 ignore start */
|
|
192
|
-
const br = buf.length === 0
|
|
193
|
-
? 0
|
|
194
|
-
: fs_1.default.readSync(this[_fd], buf, 0, buf.length, null);
|
|
195
|
-
/* c8 ignore stop */
|
|
196
|
-
if (!this[_handleChunk](br, buf)) {
|
|
197
|
-
break;
|
|
198
|
-
}
|
|
199
|
-
} while (true);
|
|
200
|
-
this[_reading] = false;
|
|
201
|
-
}
|
|
202
|
-
threw = false;
|
|
203
|
-
}
|
|
204
|
-
finally {
|
|
205
|
-
if (threw) {
|
|
206
|
-
this[_close]();
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
[_close]() {
|
|
211
|
-
if (this[_autoClose] && typeof this[_fd] === 'number') {
|
|
212
|
-
const fd = this[_fd];
|
|
213
|
-
this[_fd] = undefined;
|
|
214
|
-
fs_1.default.closeSync(fd);
|
|
215
|
-
this.emit('close');
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
exports.ReadStreamSync = ReadStreamSync;
|
|
220
|
-
class WriteStream extends events_1.default {
|
|
221
|
-
readable = false;
|
|
222
|
-
writable = true;
|
|
223
|
-
[_errored] = false;
|
|
224
|
-
[_writing] = false;
|
|
225
|
-
[_ended] = false;
|
|
226
|
-
[_queue] = [];
|
|
227
|
-
[_needDrain] = false;
|
|
228
|
-
[_path];
|
|
229
|
-
[_mode];
|
|
230
|
-
[_autoClose];
|
|
231
|
-
[_fd];
|
|
232
|
-
[_defaultFlag];
|
|
233
|
-
[_flags];
|
|
234
|
-
[_finished] = false;
|
|
235
|
-
[_pos];
|
|
236
|
-
constructor(path, opt) {
|
|
237
|
-
opt = opt || {};
|
|
238
|
-
super(opt);
|
|
239
|
-
this[_path] = path;
|
|
240
|
-
this[_fd] = typeof opt.fd === 'number' ? opt.fd : undefined;
|
|
241
|
-
this[_mode] = opt.mode === undefined ? 0o666 : opt.mode;
|
|
242
|
-
this[_pos] = typeof opt.start === 'number' ? opt.start : undefined;
|
|
243
|
-
this[_autoClose] =
|
|
244
|
-
typeof opt.autoClose === 'boolean' ? opt.autoClose : true;
|
|
245
|
-
// truncating makes no sense when writing into the middle
|
|
246
|
-
const defaultFlag = this[_pos] !== undefined ? 'r+' : 'w';
|
|
247
|
-
this[_defaultFlag] = opt.flags === undefined;
|
|
248
|
-
this[_flags] = opt.flags === undefined ? defaultFlag : opt.flags;
|
|
249
|
-
if (this[_fd] === undefined) {
|
|
250
|
-
this[_open]();
|
|
251
|
-
}
|
|
252
|
-
}
|
|
253
|
-
emit(ev, ...args) {
|
|
254
|
-
if (ev === 'error') {
|
|
255
|
-
if (this[_errored]) {
|
|
256
|
-
return false;
|
|
257
|
-
}
|
|
258
|
-
this[_errored] = true;
|
|
259
|
-
}
|
|
260
|
-
return super.emit(ev, ...args);
|
|
261
|
-
}
|
|
262
|
-
get fd() {
|
|
263
|
-
return this[_fd];
|
|
264
|
-
}
|
|
265
|
-
get path() {
|
|
266
|
-
return this[_path];
|
|
267
|
-
}
|
|
268
|
-
[_onerror](er) {
|
|
269
|
-
this[_close]();
|
|
270
|
-
this[_writing] = true;
|
|
271
|
-
this.emit('error', er);
|
|
272
|
-
}
|
|
273
|
-
[_open]() {
|
|
274
|
-
fs_1.default.open(this[_path], this[_flags], this[_mode], (er, fd) => this[_onopen](er, fd));
|
|
275
|
-
}
|
|
276
|
-
[_onopen](er, fd) {
|
|
277
|
-
if (this[_defaultFlag] &&
|
|
278
|
-
this[_flags] === 'r+' &&
|
|
279
|
-
er &&
|
|
280
|
-
er.code === 'ENOENT') {
|
|
281
|
-
this[_flags] = 'w';
|
|
282
|
-
this[_open]();
|
|
283
|
-
}
|
|
284
|
-
else if (er) {
|
|
285
|
-
this[_onerror](er);
|
|
286
|
-
}
|
|
287
|
-
else {
|
|
288
|
-
this[_fd] = fd;
|
|
289
|
-
this.emit('open', fd);
|
|
290
|
-
if (!this[_writing]) {
|
|
291
|
-
this[_flush]();
|
|
292
|
-
}
|
|
293
|
-
}
|
|
294
|
-
}
|
|
295
|
-
end(buf, enc) {
|
|
296
|
-
if (buf) {
|
|
297
|
-
//@ts-ignore
|
|
298
|
-
this.write(buf, enc);
|
|
299
|
-
}
|
|
300
|
-
this[_ended] = true;
|
|
301
|
-
// synthetic after-write logic, where drain/finish live
|
|
302
|
-
if (!this[_writing] &&
|
|
303
|
-
!this[_queue].length &&
|
|
304
|
-
typeof this[_fd] === 'number') {
|
|
305
|
-
this[_onwrite](null, 0);
|
|
306
|
-
}
|
|
307
|
-
return this;
|
|
308
|
-
}
|
|
309
|
-
write(buf, enc) {
|
|
310
|
-
if (typeof buf === 'string') {
|
|
311
|
-
buf = Buffer.from(buf, enc);
|
|
312
|
-
}
|
|
313
|
-
if (this[_ended]) {
|
|
314
|
-
this.emit('error', new Error('write() after end()'));
|
|
315
|
-
return false;
|
|
316
|
-
}
|
|
317
|
-
if (this[_fd] === undefined || this[_writing] || this[_queue].length) {
|
|
318
|
-
this[_queue].push(buf);
|
|
319
|
-
this[_needDrain] = true;
|
|
320
|
-
return false;
|
|
321
|
-
}
|
|
322
|
-
this[_writing] = true;
|
|
323
|
-
this[_write](buf);
|
|
324
|
-
return true;
|
|
325
|
-
}
|
|
326
|
-
[_write](buf) {
|
|
327
|
-
fs_1.default.write(this[_fd], buf, 0, buf.length, this[_pos], (er, bw) => this[_onwrite](er, bw));
|
|
328
|
-
}
|
|
329
|
-
[_onwrite](er, bw) {
|
|
330
|
-
if (er) {
|
|
331
|
-
this[_onerror](er);
|
|
332
|
-
}
|
|
333
|
-
else {
|
|
334
|
-
if (this[_pos] !== undefined && typeof bw === 'number') {
|
|
335
|
-
this[_pos] += bw;
|
|
336
|
-
}
|
|
337
|
-
if (this[_queue].length) {
|
|
338
|
-
this[_flush]();
|
|
339
|
-
}
|
|
340
|
-
else {
|
|
341
|
-
this[_writing] = false;
|
|
342
|
-
if (this[_ended] && !this[_finished]) {
|
|
343
|
-
this[_finished] = true;
|
|
344
|
-
this[_close]();
|
|
345
|
-
this.emit('finish');
|
|
346
|
-
}
|
|
347
|
-
else if (this[_needDrain]) {
|
|
348
|
-
this[_needDrain] = false;
|
|
349
|
-
this.emit('drain');
|
|
350
|
-
}
|
|
351
|
-
}
|
|
352
|
-
}
|
|
353
|
-
}
|
|
354
|
-
[_flush]() {
|
|
355
|
-
if (this[_queue].length === 0) {
|
|
356
|
-
if (this[_ended]) {
|
|
357
|
-
this[_onwrite](null, 0);
|
|
358
|
-
}
|
|
359
|
-
}
|
|
360
|
-
else if (this[_queue].length === 1) {
|
|
361
|
-
this[_write](this[_queue].pop());
|
|
362
|
-
}
|
|
363
|
-
else {
|
|
364
|
-
const iovec = this[_queue];
|
|
365
|
-
this[_queue] = [];
|
|
366
|
-
writev(this[_fd], iovec, this[_pos], (er, bw) => this[_onwrite](er, bw));
|
|
367
|
-
}
|
|
368
|
-
}
|
|
369
|
-
[_close]() {
|
|
370
|
-
if (this[_autoClose] && typeof this[_fd] === 'number') {
|
|
371
|
-
const fd = this[_fd];
|
|
372
|
-
this[_fd] = undefined;
|
|
373
|
-
fs_1.default.close(fd, er => er ? this.emit('error', er) : this.emit('close'));
|
|
374
|
-
}
|
|
375
|
-
}
|
|
376
|
-
}
|
|
377
|
-
exports.WriteStream = WriteStream;
|
|
378
|
-
class WriteStreamSync extends WriteStream {
|
|
379
|
-
[_open]() {
|
|
380
|
-
let fd;
|
|
381
|
-
// only wrap in a try{} block if we know we'll retry, to avoid
|
|
382
|
-
// the rethrow obscuring the error's source frame in most cases.
|
|
383
|
-
if (this[_defaultFlag] && this[_flags] === 'r+') {
|
|
384
|
-
try {
|
|
385
|
-
fd = fs_1.default.openSync(this[_path], this[_flags], this[_mode]);
|
|
386
|
-
}
|
|
387
|
-
catch (er) {
|
|
388
|
-
if (er?.code === 'ENOENT') {
|
|
389
|
-
this[_flags] = 'w';
|
|
390
|
-
return this[_open]();
|
|
391
|
-
}
|
|
392
|
-
else {
|
|
393
|
-
throw er;
|
|
394
|
-
}
|
|
395
|
-
}
|
|
396
|
-
}
|
|
397
|
-
else {
|
|
398
|
-
fd = fs_1.default.openSync(this[_path], this[_flags], this[_mode]);
|
|
399
|
-
}
|
|
400
|
-
this[_onopen](null, fd);
|
|
401
|
-
}
|
|
402
|
-
[_close]() {
|
|
403
|
-
if (this[_autoClose] && typeof this[_fd] === 'number') {
|
|
404
|
-
const fd = this[_fd];
|
|
405
|
-
this[_fd] = undefined;
|
|
406
|
-
fs_1.default.closeSync(fd);
|
|
407
|
-
this.emit('close');
|
|
408
|
-
}
|
|
409
|
-
}
|
|
410
|
-
[_write](buf) {
|
|
411
|
-
// throw the original, but try to close if it fails
|
|
412
|
-
let threw = true;
|
|
413
|
-
try {
|
|
414
|
-
this[_onwrite](null, fs_1.default.writeSync(this[_fd], buf, 0, buf.length, this[_pos]));
|
|
415
|
-
threw = false;
|
|
416
|
-
}
|
|
417
|
-
finally {
|
|
418
|
-
if (threw) {
|
|
419
|
-
try {
|
|
420
|
-
this[_close]();
|
|
421
|
-
}
|
|
422
|
-
catch {
|
|
423
|
-
// ok error
|
|
424
|
-
}
|
|
425
|
-
}
|
|
426
|
-
}
|
|
427
|
-
}
|
|
428
|
-
}
|
|
429
|
-
exports.WriteStreamSync = WriteStreamSync;
|
|
430
|
-
//# sourceMappingURL=index.js.map
|
|
1
|
+
"use strict";var __importDefault=this&&this.__importDefault||function(h){return h&&h.__esModule?h:{default:h}};Object.defineProperty(exports,`__esModule`,{value:!0}),exports.WriteStreamSync=exports.WriteStream=exports.ReadStreamSync=exports.ReadStream=void 0;const events_1=__importDefault(require(`events`)),fs_1=__importDefault(require(`fs`)),minipass_1=require(`minipass`),writev=fs_1.default.writev,_autoClose=Symbol(`_autoClose`),_close=Symbol(`_close`),_ended=Symbol(`_ended`),_fd=Symbol(`_fd`),_finished=Symbol(`_finished`),_flags=Symbol(`_flags`),_flush=Symbol(`_flush`),_handleChunk=Symbol(`_handleChunk`),_makeBuf=Symbol(`_makeBuf`),_mode=Symbol(`_mode`),_needDrain=Symbol(`_needDrain`),_onerror=Symbol(`_onerror`),_onopen=Symbol(`_onopen`),_onread=Symbol(`_onread`),_onwrite=Symbol(`_onwrite`),_open=Symbol(`_open`),_path=Symbol(`_path`),_pos=Symbol(`_pos`),_queue=Symbol(`_queue`),_read=Symbol(`_read`),_readSize=Symbol(`_readSize`),_reading=Symbol(`_reading`),_remain=Symbol(`_remain`),_size=Symbol(`_size`),_write=Symbol(`_write`),_writing=Symbol(`_writing`),_defaultFlag=Symbol(`_defaultFlag`),_errored=Symbol(`_errored`);class ReadStream extends minipass_1.Minipass{[_errored]=!1;[_fd];[_path];[_readSize];[_reading]=!1;[_size];[_remain];[_autoClose];constructor(h,F){if(F||={},super(F),this.readable=!0,this.writable=!1,typeof h!=`string`)throw TypeError(`path must be a string`);this[_errored]=!1,this[_fd]=typeof F.fd==`number`?F.fd:void 0,this[_path]=h,this[_readSize]=F.readSize||16*1024*1024,this[_reading]=!1,this[_size]=typeof F.size==`number`?F.size:1/0,this[_remain]=this[_size],this[_autoClose]=typeof F.autoClose==`boolean`?F.autoClose:!0,typeof this[_fd]==`number`?this[_read]():this[_open]()}get fd(){return this[_fd]}get path(){return this[_path]}write(){throw TypeError(`this is a readable stream`)}end(){throw TypeError(`this is a readable stream`)}[_open](){fs_1.default.open(this[_path],`r`,(h,F)=>this[_onopen](h,F))}[_onopen](h,F){h?this[_onerror](h):(this[_fd]=F,this.emit(`open`,F),this[_read]())}[_makeBuf](){return Buffer.allocUnsafe(Math.min(this[_readSize],this[_remain]))}[_read](){if(!this[_reading]){this[_reading]=!0;let h=this[_makeBuf]();if(h.length===0)return process.nextTick(()=>this[_onread](null,0,h));fs_1.default.read(this[_fd],h,0,h.length,null,(h,F,I)=>this[_onread](h,F,I))}}[_onread](h,F,I){this[_reading]=!1,h?this[_onerror](h):this[_handleChunk](F,I)&&this[_read]()}[_close](){if(this[_autoClose]&&typeof this[_fd]==`number`){let h=this[_fd];this[_fd]=void 0,fs_1.default.close(h,h=>h?this.emit(`error`,h):this.emit(`close`))}}[_onerror](h){this[_reading]=!0,this[_close](),this.emit(`error`,h)}[_handleChunk](h,F){let I=!1;return this[_remain]-=h,h>0&&(I=super.write(h<F.length?F.subarray(0,h):F)),(h===0||this[_remain]<=0)&&(I=!1,this[_close](),super.end()),I}emit(h,...F){switch(h){case`prefinish`:case`finish`:return!1;case`drain`:return typeof this[_fd]==`number`&&this[_read](),!1;case`error`:return this[_errored]?!1:(this[_errored]=!0,super.emit(h,...F));default:return super.emit(h,...F)}}}exports.ReadStream=ReadStream;class ReadStreamSync extends ReadStream{[_open](){let h=!0;try{this[_onopen](null,fs_1.default.openSync(this[_path],`r`)),h=!1}finally{h&&this[_close]()}}[_read](){let h=!0;try{if(!this[_reading]){this[_reading]=!0;do{let h=this[_makeBuf](),F=h.length===0?0:fs_1.default.readSync(this[_fd],h,0,h.length,null);if(!this[_handleChunk](F,h))break}while(!0);this[_reading]=!1}h=!1}finally{h&&this[_close]()}}[_close](){if(this[_autoClose]&&typeof this[_fd]==`number`){let h=this[_fd];this[_fd]=void 0,fs_1.default.closeSync(h),this.emit(`close`)}}}exports.ReadStreamSync=ReadStreamSync;class WriteStream extends events_1.default{readable=!1;writable=!0;[_errored]=!1;[_writing]=!1;[_ended]=!1;[_queue]=[];[_needDrain]=!1;[_path];[_mode];[_autoClose];[_fd];[_defaultFlag];[_flags];[_finished]=!1;[_pos];constructor(h,F){F||={},super(F),this[_path]=h,this[_fd]=typeof F.fd==`number`?F.fd:void 0,this[_mode]=F.mode===void 0?438:F.mode,this[_pos]=typeof F.start==`number`?F.start:void 0,this[_autoClose]=typeof F.autoClose==`boolean`?F.autoClose:!0;let I=this[_pos]===void 0?`w`:`r+`;this[_defaultFlag]=F.flags===void 0,this[_flags]=F.flags===void 0?I:F.flags,this[_fd]===void 0&&this[_open]()}emit(h,...F){if(h===`error`){if(this[_errored])return!1;this[_errored]=!0}return super.emit(h,...F)}get fd(){return this[_fd]}get path(){return this[_path]}[_onerror](h){this[_close](),this[_writing]=!0,this.emit(`error`,h)}[_open](){fs_1.default.open(this[_path],this[_flags],this[_mode],(h,F)=>this[_onopen](h,F))}[_onopen](h,F){this[_defaultFlag]&&this[_flags]===`r+`&&h&&h.code===`ENOENT`?(this[_flags]=`w`,this[_open]()):h?this[_onerror](h):(this[_fd]=F,this.emit(`open`,F),this[_writing]||this[_flush]())}end(h,F){return h&&this.write(h,F),this[_ended]=!0,!this[_writing]&&!this[_queue].length&&typeof this[_fd]==`number`&&this[_onwrite](null,0),this}write(h,F){return typeof h==`string`&&(h=Buffer.from(h,F)),this[_ended]?(this.emit(`error`,Error(`write() after end()`)),!1):this[_fd]===void 0||this[_writing]||this[_queue].length?(this[_queue].push(h),this[_needDrain]=!0,!1):(this[_writing]=!0,this[_write](h),!0)}[_write](h){fs_1.default.write(this[_fd],h,0,h.length,this[_pos],(h,F)=>this[_onwrite](h,F))}[_onwrite](h,F){h?this[_onerror](h):(this[_pos]!==void 0&&typeof F==`number`&&(this[_pos]+=F),this[_queue].length?this[_flush]():(this[_writing]=!1,this[_ended]&&!this[_finished]?(this[_finished]=!0,this[_close](),this.emit(`finish`)):this[_needDrain]&&(this[_needDrain]=!1,this.emit(`drain`))))}[_flush](){if(this[_queue].length===0)this[_ended]&&this[_onwrite](null,0);else if(this[_queue].length===1)this[_write](this[_queue].pop());else{let h=this[_queue];this[_queue]=[],writev(this[_fd],h,this[_pos],(h,F)=>this[_onwrite](h,F))}}[_close](){if(this[_autoClose]&&typeof this[_fd]==`number`){let h=this[_fd];this[_fd]=void 0,fs_1.default.close(h,h=>h?this.emit(`error`,h):this.emit(`close`))}}}exports.WriteStream=WriteStream;class WriteStreamSync extends WriteStream{[_open](){let h;if(this[_defaultFlag]&&this[_flags]===`r+`)try{h=fs_1.default.openSync(this[_path],this[_flags],this[_mode])}catch(h){if(h?.code===`ENOENT`)return this[_flags]=`w`,this[_open]();throw h}else h=fs_1.default.openSync(this[_path],this[_flags],this[_mode]);this[_onopen](null,h)}[_close](){if(this[_autoClose]&&typeof this[_fd]==`number`){let h=this[_fd];this[_fd]=void 0,fs_1.default.closeSync(h),this.emit(`close`)}}[_write](h){let F=!0;try{this[_onwrite](null,fs_1.default.writeSync(this[_fd],h,0,h.length,this[_pos])),F=!1}finally{if(F)try{this[_close]()}catch{}}}}exports.WriteStreamSync=WriteStreamSync;
|