@atlaspack/core 2.13.2-dev.3689 → 2.14.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (85) hide show
  1. package/CHANGELOG.md +61 -0
  2. package/package.json +20 -20
  3. package/src/Atlaspack.js +3 -2
  4. package/src/atlaspack-v3/AtlaspackV3.js +25 -9
  5. package/src/requests/WriteBundlesRequest.js +31 -22
  6. package/LICENSE +0 -201
  7. package/lib/AssetGraph.js +0 -521
  8. package/lib/Atlaspack.js +0 -676
  9. package/lib/AtlaspackConfig.js +0 -298
  10. package/lib/AtlaspackConfig.schema.js +0 -103
  11. package/lib/BundleGraph.js +0 -1527
  12. package/lib/CommittedAsset.js +0 -155
  13. package/lib/Dependency.js +0 -136
  14. package/lib/Environment.js +0 -144
  15. package/lib/IdentifierRegistry.js +0 -36
  16. package/lib/InternalConfig.js +0 -56
  17. package/lib/PackagerRunner.js +0 -525
  18. package/lib/ReporterRunner.js +0 -151
  19. package/lib/RequestTracker.js +0 -1178
  20. package/lib/SymbolPropagation.js +0 -618
  21. package/lib/TargetDescriptor.schema.js +0 -118
  22. package/lib/Transformation.js +0 -522
  23. package/lib/UncommittedAsset.js +0 -348
  24. package/lib/Validation.js +0 -203
  25. package/lib/applyRuntimes.js +0 -355
  26. package/lib/assetUtils.js +0 -205
  27. package/lib/atlaspack-v3/AtlaspackV3.js +0 -57
  28. package/lib/atlaspack-v3/NapiWorkerPool.js +0 -71
  29. package/lib/atlaspack-v3/fs.js +0 -39
  30. package/lib/atlaspack-v3/index.js +0 -26
  31. package/lib/atlaspack-v3/jsCallable.js +0 -20
  32. package/lib/atlaspack-v3/worker/compat/asset-symbols.js +0 -197
  33. package/lib/atlaspack-v3/worker/compat/bitflags.js +0 -84
  34. package/lib/atlaspack-v3/worker/compat/dependency.js +0 -44
  35. package/lib/atlaspack-v3/worker/compat/environment.js +0 -57
  36. package/lib/atlaspack-v3/worker/compat/index.js +0 -104
  37. package/lib/atlaspack-v3/worker/compat/mutable-asset.js +0 -164
  38. package/lib/atlaspack-v3/worker/compat/plugin-config.js +0 -78
  39. package/lib/atlaspack-v3/worker/compat/plugin-logger.js +0 -29
  40. package/lib/atlaspack-v3/worker/compat/plugin-options.js +0 -113
  41. package/lib/atlaspack-v3/worker/compat/plugin-tracer.js +0 -12
  42. package/lib/atlaspack-v3/worker/compat/target.js +0 -17
  43. package/lib/atlaspack-v3/worker/index.js +0 -3
  44. package/lib/atlaspack-v3/worker/worker.js +0 -280
  45. package/lib/constants.js +0 -21
  46. package/lib/dumpGraphToGraphViz.js +0 -206
  47. package/lib/index.js +0 -70
  48. package/lib/loadAtlaspackPlugin.js +0 -115
  49. package/lib/loadDotEnv.js +0 -54
  50. package/lib/projectPath.js +0 -112
  51. package/lib/public/Asset.js +0 -259
  52. package/lib/public/Bundle.js +0 -236
  53. package/lib/public/BundleGraph.js +0 -279
  54. package/lib/public/BundleGroup.js +0 -50
  55. package/lib/public/Config.js +0 -202
  56. package/lib/public/Dependency.js +0 -131
  57. package/lib/public/Environment.js +0 -247
  58. package/lib/public/MutableBundleGraph.js +0 -204
  59. package/lib/public/PluginOptions.js +0 -71
  60. package/lib/public/Symbols.js +0 -247
  61. package/lib/public/Target.js +0 -64
  62. package/lib/registerCoreWithSerializer.js +0 -51
  63. package/lib/requests/AssetGraphRequest.js +0 -432
  64. package/lib/requests/AssetGraphRequestRust.js +0 -220
  65. package/lib/requests/AssetRequest.js +0 -132
  66. package/lib/requests/AtlaspackBuildRequest.js +0 -79
  67. package/lib/requests/AtlaspackConfigRequest.js +0 -479
  68. package/lib/requests/BundleGraphRequest.js +0 -485
  69. package/lib/requests/ConfigRequest.js +0 -203
  70. package/lib/requests/DevDepRequest.js +0 -193
  71. package/lib/requests/EntryRequest.js +0 -295
  72. package/lib/requests/PackageRequest.js +0 -88
  73. package/lib/requests/PathRequest.js +0 -357
  74. package/lib/requests/TargetRequest.js +0 -1179
  75. package/lib/requests/ValidationRequest.js +0 -66
  76. package/lib/requests/WriteBundleRequest.js +0 -252
  77. package/lib/requests/WriteBundlesRequest.js +0 -153
  78. package/lib/requests/asset-graph-diff.js +0 -128
  79. package/lib/requests/asset-graph-dot.js +0 -131
  80. package/lib/resolveOptions.js +0 -265
  81. package/lib/serializerCore.browser.js +0 -29
  82. package/lib/summarizeRequest.js +0 -55
  83. package/lib/types.js +0 -35
  84. package/lib/utils.js +0 -160
  85. package/lib/worker.js +0 -184
@@ -1,164 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.MutableAsset = void 0;
7
- function _sourceMap() {
8
- const data = _interopRequireDefault(require("@parcel/source-map"));
9
- _sourceMap = function () {
10
- return data;
11
- };
12
- return data;
13
- }
14
- function _stream() {
15
- const data = require("stream");
16
- _stream = function () {
17
- return data;
18
- };
19
- return data;
20
- }
21
- var _bitflags = require("./bitflags");
22
- var _assetSymbols = require("./asset-symbols");
23
- function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
24
- function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
25
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
26
- class MutableAsset {
27
- #astDirty;
28
- #ast;
29
- #contents;
30
- #inner;
31
- #map;
32
- #projectRoot;
33
- #sourceMap;
34
- get astGenerator() {
35
- throw new Error('get MutableAsset.astGenerator');
36
- }
37
- set astGenerator(value) {
38
- throw new Error('set MutableAsset.astGenerator');
39
- }
40
- constructor(asset, contents, env, fs, map, projectRoot) {
41
- this.bundleBehavior = _bitflags.bundleBehaviorMap.fromNullable(asset.bundleBehavior);
42
- this.env = env;
43
- this.filePath = asset.filePath;
44
- this.fs = fs;
45
- this.id = asset.id;
46
- this.isBundleSplittable = asset.isBundleSplittable;
47
- this.isSource = asset.isSource;
48
- this.meta = asset.meta;
49
- this.pipeline = asset.pipeline;
50
- this.query = new URLSearchParams(asset.query);
51
- this.sideEffects = asset.sideEffects;
52
- this.stats = asset.stats;
53
- this.symbols = new _assetSymbols.MutableAssetSymbols(asset.symbols);
54
- this.type = asset.type;
55
- this.uniqueKey = asset.uniqueKey;
56
- this.#astDirty = false;
57
- this.#contents = contents;
58
- this.#inner = asset;
59
- this.#map = map;
60
- this.#projectRoot = projectRoot;
61
- }
62
-
63
- // eslint-disable-next-line require-await
64
- async getAST() {
65
- return this.#ast;
66
- }
67
- setAST(ast) {
68
- this.#astDirty = true;
69
- this.#ast = ast;
70
- }
71
- isASTDirty() {
72
- return this.#astDirty;
73
- }
74
-
75
- // eslint-disable-next-line require-await
76
- async getCode() {
77
- return this.#contents.toString();
78
- }
79
- setCode(code) {
80
- this.#contents = Buffer.from(code);
81
- }
82
-
83
- // eslint-disable-next-line require-await
84
- async getBuffer() {
85
- return this.#contents;
86
- }
87
- setBuffer(buf) {
88
- this.#contents = buf;
89
- }
90
- getStream() {
91
- return _stream().Readable.from(this.#contents);
92
- }
93
- setStream(stream) {
94
- const data = [];
95
- stream.on('data', chunk => {
96
- data.push(chunk);
97
- });
98
- stream.on('end', () => {
99
- this.#contents = Buffer.concat(data);
100
- });
101
- stream.on('error', () => {
102
- throw new Error('MutableAsset.setStream()');
103
- });
104
- }
105
- getMap() {
106
- // Only create the source map if it is requested
107
- if (!this.#sourceMap && this.#map && typeof this.#map === 'string') {
108
- let sourceMap = new (_sourceMap().default)(this.#projectRoot);
109
- // $FlowFixMe Flow is dumb
110
- sourceMap.addVLQMap(JSON.parse(this.#map));
111
- this.#sourceMap = sourceMap;
112
- }
113
- return Promise.resolve(this.#sourceMap);
114
- }
115
-
116
- // eslint-disable-next-line no-unused-vars
117
- setMap(sourceMap) {
118
- this.isMapDirty = true;
119
- this.#sourceMap = sourceMap;
120
- }
121
- getMapBuffer() {
122
- throw new Error('getMapBuffer() is considered an internal implementation detail, please use getMap() instead');
123
- }
124
- getDependencies() {
125
- throw new Error('MutableAsset.getDependencies');
126
- }
127
-
128
- // eslint-disable-next-line no-unused-vars
129
- addDependency() {
130
- throw new Error('MutableAsset.addDependency()');
131
- }
132
-
133
- // eslint-disable-next-line no-unused-vars
134
- addURLDependency() {
135
- throw new Error('MutableAsset.addURLDependency()');
136
- }
137
-
138
- // eslint-disable-next-line no-unused-vars
139
- setEnvironment() {
140
- throw new Error('MutableAsset.setEnvironment()');
141
- }
142
-
143
- // eslint-disable-next-line no-unused-vars
144
- invalidateOnFileChange() {
145
- // TODO: Forward invalidations to Rust
146
- }
147
-
148
- // eslint-disable-next-line no-unused-vars
149
- invalidateOnFileCreate() {
150
- // TODO: Forward invalidations to Rust
151
- }
152
-
153
- // eslint-disable-next-line no-unused-vars
154
- invalidateOnEnvChange() {
155
- // TODO: Forward invalidations to Rust
156
- }
157
- invalidateOnStartup() {
158
- // TODO: Forward invalidations to Rust
159
- }
160
- invalidateOnBuild() {
161
- // TODO: Forward invalidations to Rust
162
- }
163
- }
164
- exports.MutableAsset = MutableAsset;
@@ -1,78 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.PluginConfig = void 0;
7
- var _Config = _interopRequireDefault(require("../../../public/Config"));
8
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
9
- class PluginConfig {
10
- #projectRoot;
11
- #inner;
12
- constructor({
13
- env,
14
- isSource,
15
- searchPath,
16
- projectRoot,
17
- fs,
18
- packageManager
19
- }) {
20
- this.env = env;
21
- this.isSource = isSource;
22
- this.searchPath = searchPath;
23
- this.#inner = new _Config.default(
24
- // $FlowFixMe
25
- {
26
- invalidateOnConfigKeyChange: [],
27
- invalidateOnFileCreate: [],
28
- invalidateOnFileChange: new Set(),
29
- devDeps: [],
30
- // $FlowFixMe
31
- searchPath: searchPath.replace(projectRoot + '/', '')
32
- },
33
- // $FlowFixMe
34
- {
35
- projectRoot,
36
- inputFS: fs,
37
- outputFS: fs,
38
- packageManager
39
- });
40
- }
41
-
42
- // eslint-disable-next-line no-unused-vars
43
- invalidateOnFileChange() {}
44
-
45
- // eslint-disable-next-line no-unused-vars
46
- invalidateOnFileCreate() {}
47
-
48
- // eslint-disable-next-line no-unused-vars
49
- invalidateOnEnvChange() {}
50
- invalidateOnStartup() {}
51
- invalidateOnBuild() {}
52
-
53
- // eslint-disable-next-line no-unused-vars
54
- addDevDependency() {}
55
-
56
- // eslint-disable-next-line no-unused-vars
57
- setCacheKey() {}
58
- getConfig(
59
- // eslint-disable-next-line no-unused-vars
60
- filePaths,
61
- // eslint-disable-next-line no-unused-vars
62
- options) {
63
- return this.#inner.getConfig(filePaths, options);
64
- }
65
- getConfigFrom(
66
- // eslint-disable-next-line no-unused-vars
67
- searchPath,
68
- // eslint-disable-next-line no-unused-vars
69
- filePaths,
70
- // eslint-disable-next-line no-unused-vars
71
- options) {
72
- return this.#inner.getConfigFrom(searchPath, filePaths, options);
73
- }
74
- getPackage() {
75
- return this.#inner.getPackage();
76
- }
77
- }
78
- exports.PluginConfig = PluginConfig;
@@ -1,29 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.PluginLogger = void 0;
7
- class PluginLogger {
8
- verbose(diagnostic) {
9
- // eslint-disable-next-line no-console
10
- console.log(diagnostic);
11
- }
12
- info(diagnostic) {
13
- // eslint-disable-next-line no-console
14
- console.info(diagnostic);
15
- }
16
- log(diagnostic) {
17
- // eslint-disable-next-line no-console
18
- console.log(diagnostic);
19
- }
20
- warn(diagnostic) {
21
- // eslint-disable-next-line no-console
22
- console.warn(diagnostic);
23
- }
24
- error(input) {
25
- // eslint-disable-next-line no-console
26
- console.error(input);
27
- }
28
- }
29
- exports.PluginLogger = PluginLogger;
@@ -1,113 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.PluginOptions = void 0;
7
- class PluginOptions {
8
- #options;
9
- get env() {
10
- if (!('env' in this.#options)) {
11
- return process.env;
12
- // throw new Error('PluginOptions.env');
13
- }
14
-
15
- return this.#options.env;
16
- }
17
- get projectRoot() {
18
- if (!('projectRoot' in this.#options)) {
19
- throw new Error('PluginOptions.projectRoot');
20
- }
21
- return this.#options.projectRoot;
22
- }
23
- get packageManager() {
24
- if (!('packageManager' in this.#options)) {
25
- throw new Error('PluginOptions.packageManager');
26
- }
27
- return this.#options.packageManager;
28
- }
29
- get mode() {
30
- if (!('mode' in this.#options)) {
31
- throw new Error('PluginOptions.mode');
32
- }
33
- return this.#options.mode;
34
- }
35
- get parcelVersion() {
36
- if (!('parcelVersion' in this.#options)) {
37
- return 'UNKNOWN VERSION';
38
- // throw new Error('PluginOptions.parcelVersion');
39
- }
40
-
41
- return this.#options.parcelVersion;
42
- }
43
- get hmrOptions() {
44
- if (!('hmrOptions' in this.#options)) {
45
- throw new Error('PluginOptions.hmrOptions');
46
- }
47
- return this.#options.hmrOptions;
48
- }
49
- get serveOptions() {
50
- if (!('serveOptions' in this.#options)) {
51
- throw new Error('PluginOptions.serveOptions');
52
- }
53
- return this.#options.serveOptions;
54
- }
55
- get shouldBuildLazily() {
56
- if (!('shouldBuildLazily' in this.#options)) {
57
- throw new Error('PluginOptions.shouldBuildLazily');
58
- }
59
- return this.#options.shouldBuildLazily;
60
- }
61
- get shouldAutoInstall() {
62
- if (!('shouldAutoInstall' in this.#options)) {
63
- throw new Error('PluginOptions.shouldAutoInstall');
64
- }
65
- return this.#options.shouldAutoInstall;
66
- }
67
- get logLevel() {
68
- if (!('logLevel' in this.#options)) {
69
- throw new Error('PluginOptions.logLevel');
70
- }
71
- return this.#options.logLevel;
72
- }
73
- get cacheDir() {
74
- if (!('cacheDir' in this.#options)) {
75
- throw new Error('PluginOptions.cacheDir');
76
- }
77
- return this.#options.cacheDir;
78
- }
79
- get inputFS() {
80
- if (!('inputFS' in this.#options)) {
81
- throw new Error('PluginOptions.inputFS');
82
- }
83
- return this.#options.inputFS;
84
- }
85
- get outputFS() {
86
- if (!('outputFS' in this.#options)) {
87
- throw new Error('PluginOptions.outputFS');
88
- }
89
- return this.#options.outputFS;
90
- }
91
- get instanceId() {
92
- if (!('instanceId' in this.#options)) {
93
- throw new Error('PluginOptions.instanceId');
94
- }
95
- return this.#options.instanceId;
96
- }
97
- get detailedReport() {
98
- if (!('detailedReport' in this.#options)) {
99
- throw new Error('PluginOptions.detailedReport');
100
- }
101
- return this.#options.detailedReport;
102
- }
103
- get featureFlags() {
104
- if (!('featureFlags' in this.#options)) {
105
- throw new Error('PluginOptions.featureFlags');
106
- }
107
- return this.#options.featureFlags;
108
- }
109
- constructor(options) {
110
- this.#options = options;
111
- }
112
- }
113
- exports.PluginOptions = PluginOptions;
@@ -1,12 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.PluginTracer = void 0;
7
- class PluginTracer {
8
- createMeasurement() {
9
- throw new Error('PluginTracer.createMeasurement');
10
- }
11
- }
12
- exports.PluginTracer = PluginTracer;
@@ -1,17 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.Target = void 0;
7
- class Target {
8
- constructor(inner, env) {
9
- this.distDir = inner.distDir;
10
- this.distEntry = inner.distEntry;
11
- this.name = inner.name;
12
- this.publicUrl = inner.publicUrl;
13
- this.loc = inner.loc;
14
- this.env = env;
15
- }
16
- }
17
- exports.Target = Target;
@@ -1,3 +0,0 @@
1
- "use strict";
2
-
3
- require('./worker');
@@ -1,280 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.AtlaspackWorker = void 0;
7
- function _assert() {
8
- const data = _interopRequireDefault(require("assert"));
9
- _assert = function () {
10
- return data;
11
- };
12
- return data;
13
- }
14
- function napi() {
15
- const data = _interopRequireWildcard(require("@atlaspack/rust"));
16
- napi = function () {
17
- return data;
18
- };
19
- return data;
20
- }
21
- function _fs() {
22
- const data = require("@atlaspack/fs");
23
- _fs = function () {
24
- return data;
25
- };
26
- return data;
27
- }
28
- function _packageManager() {
29
- const data = require("@atlaspack/package-manager");
30
- _packageManager = function () {
31
- return data;
32
- };
33
- return data;
34
- }
35
- function _worker_threads() {
36
- const data = require("worker_threads");
37
- _worker_threads = function () {
38
- return data;
39
- };
40
- return data;
41
- }
42
- function _module() {
43
- const data = _interopRequireWildcard(require("module"));
44
- _module = function () {
45
- return data;
46
- };
47
- return data;
48
- }
49
- var _jsCallable = require("../jsCallable");
50
- var _compat = require("./compat");
51
- function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
52
- function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
53
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
54
- const CONFIG = Symbol.for('parcel-plugin-config');
55
- class AtlaspackWorker {
56
- #resolvers;
57
- #transformers;
58
- #fs;
59
- constructor() {
60
- this.#resolvers = new Map();
61
- this.#transformers = new Map();
62
- this.#fs = new (_fs().NodeFS)();
63
- }
64
- loadPlugin = (0, _jsCallable.jsCallable)(async ({
65
- kind,
66
- specifier,
67
- resolveFrom
68
- }) => {
69
- let customRequire = _module().createRequire(resolveFrom);
70
- let resolvedPath = customRequire.resolve(specifier);
71
- // $FlowFixMe
72
- let resolvedModule = await import(resolvedPath);
73
- let instance = undefined;
74
- if (resolvedModule.default && resolvedModule.default[CONFIG]) {
75
- instance = resolvedModule.default[CONFIG];
76
- } else if (resolvedModule.default && resolvedModule.default.default && resolvedModule.default.default[CONFIG]) {
77
- instance = resolvedModule.default.default[CONFIG];
78
- } else {
79
- throw new Error(`Plugin could not be resolved\n\t${kind}\n\t${resolveFrom}\n\t${specifier}`);
80
- }
81
- switch (kind) {
82
- case 'resolver':
83
- this.#resolvers.set(specifier, {
84
- resolver: instance
85
- });
86
- break;
87
- case 'transformer':
88
- this.#transformers.set(specifier, {
89
- transformer: instance
90
- });
91
- break;
92
- }
93
- });
94
- runResolverResolve = (0, _jsCallable.jsCallable)(async ({
95
- key,
96
- dependency: napiDependency,
97
- specifier,
98
- pipeline,
99
- pluginOptions
100
- }) => {
101
- const state = this.#resolvers.get(key);
102
- if (!state) {
103
- throw new Error(`Resolver not found: ${key}`);
104
- }
105
- let packageManager = state.packageManager;
106
- if (!packageManager) {
107
- packageManager = new (_packageManager().NodePackageManager)(this.#fs, pluginOptions.projectRoot);
108
- state.packageManager = packageManager;
109
- }
110
- const env = new _compat.Environment(napiDependency.env);
111
- const dependency = new _compat.Dependency(napiDependency, env);
112
- const defaultOptions = {
113
- logger: new _compat.PluginLogger(),
114
- tracer: new _compat.PluginTracer(),
115
- options: new _compat.PluginOptions({
116
- ...pluginOptions,
117
- packageManager,
118
- shouldAutoInstall: false,
119
- inputFS: this.#fs,
120
- outputFS: this.#fs
121
- })
122
- };
123
- if (!('config' in state)) {
124
- var _state$resolver$loadC, _state$resolver;
125
- state.config = await ((_state$resolver$loadC = (_state$resolver = state.resolver).loadConfig) === null || _state$resolver$loadC === void 0 ? void 0 : _state$resolver$loadC.call(_state$resolver, {
126
- config: new _compat.PluginConfig({
127
- env,
128
- isSource: true,
129
- searchPath: specifier,
130
- projectRoot: pluginOptions.projectRoot,
131
- fs: this.#fs,
132
- packageManager
133
- }),
134
- ...defaultOptions
135
- }));
136
- }
137
- const result = await state.resolver.resolve({
138
- specifier,
139
- dependency,
140
- pipeline,
141
- config: state.config,
142
- ...defaultOptions
143
- });
144
- if (!result) {
145
- return {
146
- invalidations: [],
147
- resolution: {
148
- type: 'unresolved'
149
- }
150
- };
151
- }
152
- return {
153
- invalidations: [],
154
- resolution: {
155
- type: 'resolved',
156
- filePath: result.filePath || '',
157
- canDefer: result.canDefer || false,
158
- sideEffects: result.sideEffects || false,
159
- code: result.code || undefined,
160
- meta: result.meta || undefined,
161
- pipeline: result.pipeline || undefined,
162
- priority: _compat.dependencyPriorityMap.intoNullable(result.priority),
163
- query: result.query && result.query.toString()
164
- }
165
- };
166
- });
167
- runTransformerTransform = (0, _jsCallable.jsCallable)(async ({
168
- key,
169
- env: napiEnv,
170
- options,
171
- asset: innerAsset
172
- }, contents, map) => {
173
- var _transformer$loadConf;
174
- const state = this.#transformers.get(key);
175
- if (!state) {
176
- throw new Error(`Transformer not found: ${key}`);
177
- }
178
- let packageManager = state.packageManager;
179
- if (!packageManager) {
180
- packageManager = new (_packageManager().NodePackageManager)(this.#fs, options.projectRoot);
181
- state.packageManager = packageManager;
182
- }
183
- const transformer = state.transformer;
184
- const resolveFunc = (from, to) => {
185
- let customRequire = _module().createRequire(from);
186
- let resolvedPath = customRequire.resolve(to);
187
- return Promise.resolve(resolvedPath);
188
- };
189
- const env = new _compat.Environment(napiEnv);
190
- const mutableAsset = new _compat.MutableAsset(innerAsset, contents, env, this.#fs, map, options.projectRoot);
191
- const defaultOptions = {
192
- logger: new _compat.PluginLogger(),
193
- tracer: new _compat.PluginTracer(),
194
- options: new _compat.PluginOptions({
195
- ...options,
196
- packageManager,
197
- shouldAutoInstall: false,
198
- inputFS: this.#fs,
199
- outputFS: this.#fs
200
- })
201
- };
202
- const config = await ((_transformer$loadConf = transformer.loadConfig) === null || _transformer$loadConf === void 0 ? void 0 : _transformer$loadConf.call(transformer, {
203
- config: new _compat.PluginConfig({
204
- env,
205
- isSource: true,
206
- searchPath: innerAsset.filePath,
207
- projectRoot: options.projectRoot,
208
- fs: this.#fs,
209
- packageManager
210
- }),
211
- ...defaultOptions
212
- }));
213
- if (transformer.parse) {
214
- const ast = await transformer.parse({
215
- asset: mutableAsset,
216
- config,
217
- resolve: resolveFunc,
218
- ...defaultOptions
219
- });
220
- if (ast) {
221
- mutableAsset.setAST(ast);
222
- }
223
- }
224
- const result = await state.transformer.transform({
225
- asset: mutableAsset,
226
- config,
227
- resolve: resolveFunc,
228
- ...defaultOptions
229
- });
230
- if (transformer.generate) {
231
- const ast = await mutableAsset.getAST();
232
- if (ast) {
233
- // $FlowFixMe "Cannot call `transformer.generate` because undefined [1] is not a function." 🤷‍♀️
234
- const output = await transformer.generate({
235
- asset: mutableAsset,
236
- ast,
237
- ...defaultOptions
238
- });
239
- if (typeof output.content === 'string') {
240
- mutableAsset.setCode(output.content);
241
- } else if (output.content instanceof Buffer) {
242
- mutableAsset.setBuffer(output.content);
243
- } else {
244
- mutableAsset.setStream(output.content);
245
- }
246
- if (output.map) {
247
- mutableAsset.setMap(output.map);
248
- }
249
- }
250
- }
251
- (0, _assert().default)(result.length === 1, '[V3] Unimplemented: Multiple asset return from Node transformer');
252
- (0, _assert().default)(result[0] === mutableAsset, '[V3] Unimplemented: New asset returned from Node transformer');
253
- return [{
254
- id: mutableAsset.id,
255
- bundleBehavior: _compat.bundleBehaviorMap.intoNullable(mutableAsset.bundleBehavior),
256
- code: [],
257
- filePath: mutableAsset.filePath,
258
- isBundleSplittable: mutableAsset.isBundleSplittable,
259
- isSource: mutableAsset.isSource,
260
- meta: mutableAsset.meta,
261
- pipeline: mutableAsset.pipeline,
262
- // Query should be undefined if it's empty
263
- query: mutableAsset.query.toString() || undefined,
264
- sideEffects: mutableAsset.sideEffects,
265
- symbols: mutableAsset.symbols.intoNapi(),
266
- type: mutableAsset.type,
267
- uniqueKey: mutableAsset.uniqueKey
268
- }, await mutableAsset.getBuffer(),
269
- // Only send back the map if it has changed
270
- mutableAsset.isMapDirty ?
271
- // $FlowFixMe A dirty map means this will be valid
272
- JSON.stringify((await mutableAsset.getMap()).toVLQ()) : ''];
273
- });
274
- }
275
-
276
- // Create napi worker and send it back to main thread
277
- exports.AtlaspackWorker = AtlaspackWorker;
278
- const worker = new AtlaspackWorker();
279
- const napiWorker = napi().newNodejsWorker(worker);
280
- _worker_threads().parentPort === null || _worker_threads().parentPort === void 0 || _worker_threads().parentPort.postMessage(napiWorker);