@atlaspack/core 2.24.1 → 2.24.2-dev-ts-project-refs-d30e9754f.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 (86) hide show
  1. package/LICENSE +201 -0
  2. package/dist/AssetGraph.js +591 -0
  3. package/dist/Atlaspack.js +656 -0
  4. package/dist/AtlaspackConfig.js +324 -0
  5. package/dist/AtlaspackConfig.schema.js +108 -0
  6. package/dist/BundleGraph.js +1628 -0
  7. package/dist/CommittedAsset.js +142 -0
  8. package/dist/Dependency.js +125 -0
  9. package/dist/Environment.js +132 -0
  10. package/dist/EnvironmentManager.js +108 -0
  11. package/dist/IdentifierRegistry.js +38 -0
  12. package/dist/InternalConfig.js +37 -0
  13. package/dist/PackagerRunner.js +531 -0
  14. package/dist/ReporterRunner.js +151 -0
  15. package/dist/RequestTracker.js +1368 -0
  16. package/dist/SymbolPropagation.js +620 -0
  17. package/dist/TargetDescriptor.schema.js +143 -0
  18. package/dist/Transformation.js +487 -0
  19. package/dist/UncommittedAsset.js +315 -0
  20. package/dist/Validation.js +196 -0
  21. package/dist/applyRuntimes.js +305 -0
  22. package/dist/assetUtils.js +168 -0
  23. package/dist/atlaspack-v3/AtlaspackV3.js +70 -0
  24. package/dist/atlaspack-v3/NapiWorkerPool.js +57 -0
  25. package/dist/atlaspack-v3/fs.js +52 -0
  26. package/dist/atlaspack-v3/index.js +25 -0
  27. package/dist/atlaspack-v3/jsCallable.js +16 -0
  28. package/dist/atlaspack-v3/worker/compat/asset-symbols.js +190 -0
  29. package/dist/atlaspack-v3/worker/compat/bitflags.js +94 -0
  30. package/dist/atlaspack-v3/worker/compat/dependency.js +43 -0
  31. package/dist/atlaspack-v3/worker/compat/environment.js +57 -0
  32. package/dist/atlaspack-v3/worker/compat/index.js +25 -0
  33. package/dist/atlaspack-v3/worker/compat/mutable-asset.js +152 -0
  34. package/dist/atlaspack-v3/worker/compat/plugin-config.js +76 -0
  35. package/dist/atlaspack-v3/worker/compat/plugin-logger.js +26 -0
  36. package/dist/atlaspack-v3/worker/compat/plugin-options.js +122 -0
  37. package/dist/atlaspack-v3/worker/compat/plugin-tracer.js +10 -0
  38. package/dist/atlaspack-v3/worker/compat/target.js +14 -0
  39. package/dist/atlaspack-v3/worker/worker.js +292 -0
  40. package/dist/constants.js +17 -0
  41. package/dist/dumpGraphToGraphViz.js +281 -0
  42. package/dist/index.js +62 -0
  43. package/dist/loadAtlaspackPlugin.js +128 -0
  44. package/dist/loadDotEnv.js +41 -0
  45. package/dist/projectPath.js +83 -0
  46. package/dist/public/Asset.js +279 -0
  47. package/dist/public/Bundle.js +224 -0
  48. package/dist/public/BundleGraph.js +359 -0
  49. package/dist/public/BundleGroup.js +53 -0
  50. package/dist/public/Config.js +286 -0
  51. package/dist/public/Dependency.js +138 -0
  52. package/dist/public/Environment.js +278 -0
  53. package/dist/public/MutableBundleGraph.js +277 -0
  54. package/dist/public/PluginOptions.js +80 -0
  55. package/dist/public/Symbols.js +248 -0
  56. package/dist/public/Target.js +69 -0
  57. package/dist/registerCoreWithSerializer.js +38 -0
  58. package/dist/requests/AssetGraphRequest.js +429 -0
  59. package/dist/requests/AssetGraphRequestRust.js +246 -0
  60. package/dist/requests/AssetRequest.js +130 -0
  61. package/dist/requests/AtlaspackBuildRequest.js +60 -0
  62. package/dist/requests/AtlaspackConfigRequest.js +490 -0
  63. package/dist/requests/BundleGraphRequest.js +441 -0
  64. package/dist/requests/ConfigRequest.js +222 -0
  65. package/dist/requests/DevDepRequest.js +204 -0
  66. package/dist/requests/EntryRequest.js +314 -0
  67. package/dist/requests/PackageRequest.js +65 -0
  68. package/dist/requests/PathRequest.js +349 -0
  69. package/dist/requests/TargetRequest.js +1310 -0
  70. package/dist/requests/ValidationRequest.js +49 -0
  71. package/dist/requests/WriteBundleRequest.js +254 -0
  72. package/dist/requests/WriteBundlesRequest.js +165 -0
  73. package/dist/requests/asset-graph-diff.js +126 -0
  74. package/dist/requests/asset-graph-dot.js +131 -0
  75. package/dist/resolveOptions.js +268 -0
  76. package/dist/rustWorkerThreadDylibHack.js +19 -0
  77. package/dist/serializerCore.browser.js +43 -0
  78. package/dist/summarizeRequest.js +39 -0
  79. package/dist/types.js +31 -0
  80. package/dist/utils.js +172 -0
  81. package/dist/worker.js +130 -0
  82. package/lib/AssetGraph.js +1 -0
  83. package/package.json +22 -22
  84. package/src/AssetGraph.ts +1 -0
  85. package/tsconfig.json +55 -2
  86. package/tsconfig.tsbuildinfo +1 -0
@@ -0,0 +1,76 @@
1
+ "use strict";
2
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
3
+ if (kind === "m") throw new TypeError("Private method is not writable");
4
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
5
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
6
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
7
+ };
8
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
9
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
10
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
11
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
12
+ };
13
+ var __importDefault = (this && this.__importDefault) || function (mod) {
14
+ return (mod && mod.__esModule) ? mod : { "default": mod };
15
+ };
16
+ var _PluginConfig_projectRoot, _PluginConfig_inner;
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.PluginConfig = void 0;
19
+ const Config_1 = __importDefault(require("../../../public/Config"));
20
+ class PluginConfig {
21
+ constructor({ env, isSource, searchPath, projectRoot, fs, packageManager, }) {
22
+ // @ts-expect-error TS2564
23
+ _PluginConfig_projectRoot.set(this, void 0);
24
+ _PluginConfig_inner.set(this, void 0);
25
+ this.env = env;
26
+ this.isSource = isSource;
27
+ this.searchPath = searchPath;
28
+ __classPrivateFieldSet(this, _PluginConfig_inner, new Config_1.default(
29
+ // @ts-expect-error TS2345
30
+ {
31
+ invalidateOnConfigKeyChange: [],
32
+ invalidateOnFileCreate: [],
33
+ invalidateOnFileChange: new Set(),
34
+ devDeps: [],
35
+ searchPath: searchPath.replace(projectRoot + '/', ''),
36
+ }, {
37
+ projectRoot,
38
+ inputFS: fs,
39
+ outputFS: fs,
40
+ packageManager,
41
+ }), "f");
42
+ }
43
+ // eslint-disable-next-line no-unused-vars
44
+ invalidateOnFileChange(filePath) { }
45
+ // eslint-disable-next-line no-unused-vars
46
+ invalidateOnFileCreate(invalidations) { }
47
+ // eslint-disable-next-line no-unused-vars
48
+ invalidateOnEnvChange(invalidation) { }
49
+ invalidateOnStartup() { }
50
+ invalidateOnBuild() { }
51
+ // eslint-disable-next-line no-unused-vars
52
+ addDevDependency(options) { }
53
+ // eslint-disable-next-line no-unused-vars
54
+ setCacheKey(key) { }
55
+ getConfig(
56
+ // eslint-disable-next-line no-unused-vars
57
+ filePaths,
58
+ // eslint-disable-next-line no-unused-vars
59
+ options) {
60
+ return __classPrivateFieldGet(this, _PluginConfig_inner, "f").getConfig(filePaths, options);
61
+ }
62
+ getConfigFrom(
63
+ // eslint-disable-next-line no-unused-vars
64
+ searchPath,
65
+ // eslint-disable-next-line no-unused-vars
66
+ filePaths,
67
+ // eslint-disable-next-line no-unused-vars
68
+ options) {
69
+ return __classPrivateFieldGet(this, _PluginConfig_inner, "f").getConfigFrom(searchPath, filePaths, options);
70
+ }
71
+ getPackage() {
72
+ return __classPrivateFieldGet(this, _PluginConfig_inner, "f").getPackage();
73
+ }
74
+ }
75
+ exports.PluginConfig = PluginConfig;
76
+ _PluginConfig_projectRoot = new WeakMap(), _PluginConfig_inner = new WeakMap();
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PluginLogger = void 0;
4
+ class PluginLogger {
5
+ verbose(diagnostic) {
6
+ // eslint-disable-next-line no-console
7
+ console.log(diagnostic);
8
+ }
9
+ info(diagnostic) {
10
+ // eslint-disable-next-line no-console
11
+ console.info(diagnostic);
12
+ }
13
+ log(diagnostic) {
14
+ // eslint-disable-next-line no-console
15
+ console.log(diagnostic);
16
+ }
17
+ warn(diagnostic) {
18
+ // eslint-disable-next-line no-console
19
+ console.warn(diagnostic);
20
+ }
21
+ error(input) {
22
+ // eslint-disable-next-line no-console
23
+ console.error(input);
24
+ }
25
+ }
26
+ exports.PluginLogger = PluginLogger;
@@ -0,0 +1,122 @@
1
+ "use strict";
2
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
3
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
4
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
5
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
6
+ };
7
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
8
+ if (kind === "m") throw new TypeError("Private method is not writable");
9
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
10
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
11
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
12
+ };
13
+ var _PluginOptions_options;
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.PluginOptions = void 0;
16
+ class PluginOptions {
17
+ get env() {
18
+ if (!('env' in __classPrivateFieldGet(this, _PluginOptions_options, "f"))) {
19
+ return process.env;
20
+ // throw new Error('PluginOptions.env');
21
+ }
22
+ return __classPrivateFieldGet(this, _PluginOptions_options, "f").env;
23
+ }
24
+ get projectRoot() {
25
+ if (!('projectRoot' in __classPrivateFieldGet(this, _PluginOptions_options, "f"))) {
26
+ throw new Error('PluginOptions.projectRoot');
27
+ }
28
+ return __classPrivateFieldGet(this, _PluginOptions_options, "f").projectRoot;
29
+ }
30
+ get packageManager() {
31
+ if (!('packageManager' in __classPrivateFieldGet(this, _PluginOptions_options, "f"))) {
32
+ throw new Error('PluginOptions.packageManager');
33
+ }
34
+ return __classPrivateFieldGet(this, _PluginOptions_options, "f").packageManager;
35
+ }
36
+ get mode() {
37
+ if (!('mode' in __classPrivateFieldGet(this, _PluginOptions_options, "f"))) {
38
+ throw new Error('PluginOptions.mode');
39
+ }
40
+ return __classPrivateFieldGet(this, _PluginOptions_options, "f").mode;
41
+ }
42
+ get parcelVersion() {
43
+ if (!('parcelVersion' in __classPrivateFieldGet(this, _PluginOptions_options, "f"))) {
44
+ return 'UNKNOWN VERSION';
45
+ // throw new Error('PluginOptions.parcelVersion');
46
+ }
47
+ return __classPrivateFieldGet(this, _PluginOptions_options, "f").parcelVersion;
48
+ }
49
+ get hmrOptions() {
50
+ if (!('hmrOptions' in __classPrivateFieldGet(this, _PluginOptions_options, "f"))) {
51
+ throw new Error('PluginOptions.hmrOptions');
52
+ }
53
+ return __classPrivateFieldGet(this, _PluginOptions_options, "f").hmrOptions;
54
+ }
55
+ get serveOptions() {
56
+ if (!('serveOptions' in __classPrivateFieldGet(this, _PluginOptions_options, "f"))) {
57
+ throw new Error('PluginOptions.serveOptions');
58
+ }
59
+ return __classPrivateFieldGet(this, _PluginOptions_options, "f").serveOptions;
60
+ }
61
+ get shouldBuildLazily() {
62
+ if (!('shouldBuildLazily' in __classPrivateFieldGet(this, _PluginOptions_options, "f"))) {
63
+ throw new Error('PluginOptions.shouldBuildLazily');
64
+ }
65
+ return __classPrivateFieldGet(this, _PluginOptions_options, "f").shouldBuildLazily;
66
+ }
67
+ get shouldAutoInstall() {
68
+ if (!('shouldAutoInstall' in __classPrivateFieldGet(this, _PluginOptions_options, "f"))) {
69
+ throw new Error('PluginOptions.shouldAutoInstall');
70
+ }
71
+ return __classPrivateFieldGet(this, _PluginOptions_options, "f").shouldAutoInstall;
72
+ }
73
+ get logLevel() {
74
+ if (!('logLevel' in __classPrivateFieldGet(this, _PluginOptions_options, "f"))) {
75
+ throw new Error('PluginOptions.logLevel');
76
+ }
77
+ return __classPrivateFieldGet(this, _PluginOptions_options, "f").logLevel;
78
+ }
79
+ get cacheDir() {
80
+ if (!('cacheDir' in __classPrivateFieldGet(this, _PluginOptions_options, "f"))) {
81
+ throw new Error('PluginOptions.cacheDir');
82
+ }
83
+ return __classPrivateFieldGet(this, _PluginOptions_options, "f").cacheDir;
84
+ }
85
+ get inputFS() {
86
+ if (!('inputFS' in __classPrivateFieldGet(this, _PluginOptions_options, "f"))) {
87
+ throw new Error('PluginOptions.inputFS');
88
+ }
89
+ return __classPrivateFieldGet(this, _PluginOptions_options, "f").inputFS;
90
+ }
91
+ get outputFS() {
92
+ if (!('outputFS' in __classPrivateFieldGet(this, _PluginOptions_options, "f"))) {
93
+ throw new Error('PluginOptions.outputFS');
94
+ }
95
+ return __classPrivateFieldGet(this, _PluginOptions_options, "f").outputFS;
96
+ }
97
+ get instanceId() {
98
+ if (!('instanceId' in __classPrivateFieldGet(this, _PluginOptions_options, "f"))) {
99
+ throw new Error('PluginOptions.instanceId');
100
+ }
101
+ return __classPrivateFieldGet(this, _PluginOptions_options, "f").instanceId;
102
+ }
103
+ get detailedReport() {
104
+ if (!('detailedReport' in __classPrivateFieldGet(this, _PluginOptions_options, "f"))) {
105
+ throw new Error('PluginOptions.detailedReport');
106
+ }
107
+ return __classPrivateFieldGet(this, _PluginOptions_options, "f").detailedReport;
108
+ }
109
+ get featureFlags() {
110
+ if (!('featureFlags' in __classPrivateFieldGet(this, _PluginOptions_options, "f"))) {
111
+ throw new Error('PluginOptions.featureFlags');
112
+ }
113
+ return __classPrivateFieldGet(this, _PluginOptions_options, "f").featureFlags;
114
+ }
115
+ constructor(options) {
116
+ _PluginOptions_options.set(this, void 0);
117
+ // @ts-expect-error TS2322
118
+ __classPrivateFieldSet(this, _PluginOptions_options, options, "f");
119
+ }
120
+ }
121
+ exports.PluginOptions = PluginOptions;
122
+ _PluginOptions_options = new WeakMap();
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PluginTracer = void 0;
4
+ class PluginTracer {
5
+ // @ts-expect-error TS2416
6
+ createMeasurement() {
7
+ throw new Error('PluginTracer.createMeasurement');
8
+ }
9
+ }
10
+ exports.PluginTracer = PluginTracer;
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Target = void 0;
4
+ class Target {
5
+ constructor(inner, env) {
6
+ this.distDir = inner.distDir;
7
+ this.distEntry = inner.distEntry;
8
+ this.name = inner.name;
9
+ this.publicUrl = inner.publicUrl;
10
+ this.loc = inner.loc;
11
+ this.env = env;
12
+ }
13
+ }
14
+ exports.Target = Target;
@@ -0,0 +1,292 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
36
+ if (kind === "m") throw new TypeError("Private method is not writable");
37
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
38
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
39
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
40
+ };
41
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
42
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
43
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
44
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
45
+ };
46
+ var __importDefault = (this && this.__importDefault) || function (mod) {
47
+ return (mod && mod.__esModule) ? mod : { "default": mod };
48
+ };
49
+ var _AtlaspackWorker_resolvers, _AtlaspackWorker_transformers, _AtlaspackWorker_fs;
50
+ Object.defineProperty(exports, "__esModule", { value: true });
51
+ exports.AtlaspackWorker = void 0;
52
+ const assert_1 = __importDefault(require("assert"));
53
+ const napi = __importStar(require("@atlaspack/rust"));
54
+ const fs_1 = require("@atlaspack/fs");
55
+ const package_manager_1 = require("@atlaspack/package-manager");
56
+ const worker_threads_1 = require("worker_threads");
57
+ const module = __importStar(require("module"));
58
+ const jsCallable_1 = require("../jsCallable");
59
+ const compat_1 = require("./compat");
60
+ const CONFIG = Symbol.for('parcel-plugin-config');
61
+ class AtlaspackWorker {
62
+ constructor() {
63
+ _AtlaspackWorker_resolvers.set(this, void 0);
64
+ _AtlaspackWorker_transformers.set(this, void 0);
65
+ _AtlaspackWorker_fs.set(this, void 0);
66
+ this.loadPlugin = (0, jsCallable_1.jsCallable)(async ({ kind, specifier, resolveFrom }) => {
67
+ let customRequire = module.createRequire(resolveFrom);
68
+ let resolvedPath = customRequire.resolve(specifier);
69
+ let resolvedModule = await import(resolvedPath);
70
+ let instance = undefined;
71
+ if (resolvedModule.default && resolvedModule.default[CONFIG]) {
72
+ instance = resolvedModule.default[CONFIG];
73
+ }
74
+ else if (resolvedModule.default &&
75
+ resolvedModule.default.default &&
76
+ resolvedModule.default.default[CONFIG]) {
77
+ instance = resolvedModule.default.default[CONFIG];
78
+ }
79
+ else {
80
+ throw new Error(`Plugin could not be resolved\n\t${kind}\n\t${resolveFrom}\n\t${specifier}`);
81
+ }
82
+ switch (kind) {
83
+ case 'resolver':
84
+ __classPrivateFieldGet(this, _AtlaspackWorker_resolvers, "f").set(specifier, { resolver: instance });
85
+ break;
86
+ case 'transformer':
87
+ __classPrivateFieldGet(this, _AtlaspackWorker_transformers, "f").set(specifier, { transformer: instance });
88
+ break;
89
+ }
90
+ });
91
+ this.runResolverResolve = (0, jsCallable_1.jsCallable)(async ({ key, dependency: napiDependency, specifier, pipeline, pluginOptions, }) => {
92
+ const state = __classPrivateFieldGet(this, _AtlaspackWorker_resolvers, "f").get(key);
93
+ if (!state) {
94
+ throw new Error(`Resolver not found: ${key}`);
95
+ }
96
+ let packageManager = state.packageManager;
97
+ if (!packageManager) {
98
+ packageManager = new package_manager_1.NodePackageManager(__classPrivateFieldGet(this, _AtlaspackWorker_fs, "f"), pluginOptions.projectRoot);
99
+ state.packageManager = packageManager;
100
+ }
101
+ const env = new compat_1.Environment(napiDependency.env);
102
+ const dependency = new compat_1.Dependency(napiDependency, env);
103
+ const defaultOptions = {
104
+ logger: new compat_1.PluginLogger(),
105
+ tracer: new compat_1.PluginTracer(),
106
+ options: new compat_1.PluginOptions({
107
+ ...pluginOptions,
108
+ packageManager,
109
+ shouldAutoInstall: false,
110
+ inputFS: __classPrivateFieldGet(this, _AtlaspackWorker_fs, "f"),
111
+ outputFS: __classPrivateFieldGet(this, _AtlaspackWorker_fs, "f"),
112
+ }),
113
+ };
114
+ if (!('config' in state)) {
115
+ // @ts-expect-error TS2345
116
+ state.config = await state.resolver.loadConfig?.({
117
+ config: new compat_1.PluginConfig({
118
+ env,
119
+ isSource: true,
120
+ searchPath: specifier,
121
+ projectRoot: pluginOptions.projectRoot,
122
+ fs: __classPrivateFieldGet(this, _AtlaspackWorker_fs, "f"),
123
+ packageManager,
124
+ }),
125
+ ...defaultOptions,
126
+ });
127
+ }
128
+ // @ts-expect-error TS2345
129
+ const result = await state.resolver.resolve({
130
+ specifier,
131
+ dependency,
132
+ pipeline,
133
+ config: state.config,
134
+ ...defaultOptions,
135
+ });
136
+ if (!result) {
137
+ return {
138
+ invalidations: [],
139
+ resolution: { type: 'unresolved' },
140
+ };
141
+ }
142
+ if (result.isExcluded) {
143
+ return {
144
+ invalidations: [],
145
+ resolution: { type: 'excluded' },
146
+ };
147
+ }
148
+ return {
149
+ invalidations: [],
150
+ resolution: {
151
+ type: 'resolved',
152
+ filePath: result.filePath || '',
153
+ canDefer: result.canDefer || false,
154
+ sideEffects: result.sideEffects || false,
155
+ code: result.code || undefined,
156
+ meta: result.meta || undefined,
157
+ pipeline: result.pipeline || undefined,
158
+ priority: compat_1.dependencyPriorityMap.intoNullable(result.priority),
159
+ query: result.query && result.query.toString(),
160
+ },
161
+ };
162
+ });
163
+ this.runTransformerTransform = (0, jsCallable_1.jsCallable)(async ({ key, env: napiEnv, options, asset: innerAsset }, contents, map) => {
164
+ const state = __classPrivateFieldGet(this, _AtlaspackWorker_transformers, "f").get(key);
165
+ if (!state) {
166
+ throw new Error(`Transformer not found: ${key}`);
167
+ }
168
+ let packageManager = state.packageManager;
169
+ if (!packageManager) {
170
+ packageManager = new package_manager_1.NodePackageManager(__classPrivateFieldGet(this, _AtlaspackWorker_fs, "f"), options.projectRoot);
171
+ state.packageManager = packageManager;
172
+ }
173
+ const transformer = state.transformer;
174
+ const resolveFunc = (from, to) => {
175
+ let customRequire = module.createRequire(from);
176
+ let resolvedPath = customRequire.resolve(to);
177
+ return Promise.resolve(resolvedPath);
178
+ };
179
+ const env = new compat_1.Environment(napiEnv);
180
+ const mutableAsset = new compat_1.MutableAsset(innerAsset,
181
+ // @ts-expect-error TS2345
182
+ contents, env, __classPrivateFieldGet(this, _AtlaspackWorker_fs, "f"), map, options.projectRoot);
183
+ const defaultOptions = {
184
+ logger: new compat_1.PluginLogger(),
185
+ tracer: new compat_1.PluginTracer(),
186
+ options: new compat_1.PluginOptions({
187
+ ...options,
188
+ packageManager,
189
+ shouldAutoInstall: false,
190
+ inputFS: __classPrivateFieldGet(this, _AtlaspackWorker_fs, "f"),
191
+ outputFS: __classPrivateFieldGet(this, _AtlaspackWorker_fs, "f"),
192
+ }),
193
+ };
194
+ // @ts-expect-error TS2345
195
+ const config = await transformer.loadConfig?.({
196
+ config: new compat_1.PluginConfig({
197
+ env,
198
+ isSource: true,
199
+ searchPath: innerAsset.filePath,
200
+ projectRoot: options.projectRoot,
201
+ fs: __classPrivateFieldGet(this, _AtlaspackWorker_fs, "f"),
202
+ packageManager,
203
+ }),
204
+ ...defaultOptions,
205
+ });
206
+ if (transformer.parse) {
207
+ const ast = await transformer.parse({
208
+ // @ts-expect-error TS2322
209
+ asset: mutableAsset,
210
+ config,
211
+ resolve: resolveFunc,
212
+ ...defaultOptions,
213
+ });
214
+ if (ast) {
215
+ mutableAsset.setAST(ast);
216
+ }
217
+ }
218
+ const result = await state.transformer.transform({
219
+ // @ts-expect-error TS2322
220
+ asset: mutableAsset,
221
+ config,
222
+ resolve: resolveFunc,
223
+ ...defaultOptions,
224
+ });
225
+ if (transformer.generate) {
226
+ const ast = await mutableAsset.getAST();
227
+ if (ast) {
228
+ const output = await transformer.generate({
229
+ // @ts-expect-error TS2322
230
+ asset: mutableAsset,
231
+ ast,
232
+ ...defaultOptions,
233
+ });
234
+ if (typeof output.content === 'string') {
235
+ mutableAsset.setCode(output.content);
236
+ }
237
+ else if (output.content instanceof Buffer) {
238
+ mutableAsset.setBuffer(output.content);
239
+ }
240
+ else {
241
+ // @ts-expect-error TS2345
242
+ mutableAsset.setStream(output.content);
243
+ }
244
+ if (output.map) {
245
+ mutableAsset.setMap(output.map);
246
+ }
247
+ }
248
+ }
249
+ (0, assert_1.default)(result.length === 1, '[V3] Unimplemented: Multiple asset return from Node transformer');
250
+ (0, assert_1.default)(result[0] === mutableAsset, '[V3] Unimplemented: New asset returned from Node transformer');
251
+ let assetBuffer = await mutableAsset.getBuffer();
252
+ // If the asset has no code, we set the buffer to null, which we can
253
+ // detect in Rust, to avoid passing back an empty buffer, which we can't.
254
+ if (assetBuffer.length === 0) {
255
+ assetBuffer = null;
256
+ }
257
+ return [
258
+ {
259
+ id: mutableAsset.id,
260
+ bundleBehavior: compat_1.bundleBehaviorMap.intoNullable(mutableAsset.bundleBehavior),
261
+ code: [],
262
+ filePath: mutableAsset.filePath,
263
+ isBundleSplittable: mutableAsset.isBundleSplittable,
264
+ isSource: mutableAsset.isSource,
265
+ meta: mutableAsset.meta,
266
+ pipeline: mutableAsset.pipeline,
267
+ // Query should be undefined if it's empty
268
+ query: mutableAsset.query.toString() || undefined,
269
+ sideEffects: mutableAsset.sideEffects,
270
+ symbols: mutableAsset.symbols.intoNapi(),
271
+ type: mutableAsset.type,
272
+ uniqueKey: mutableAsset.uniqueKey,
273
+ },
274
+ assetBuffer,
275
+ // Only send back the map if it has changed
276
+ mutableAsset.isMapDirty
277
+ ? // @ts-expect-error TS2533
278
+ JSON.stringify((await mutableAsset.getMap()).toVLQ())
279
+ : '',
280
+ ];
281
+ });
282
+ __classPrivateFieldSet(this, _AtlaspackWorker_resolvers, new Map(), "f");
283
+ __classPrivateFieldSet(this, _AtlaspackWorker_transformers, new Map(), "f");
284
+ __classPrivateFieldSet(this, _AtlaspackWorker_fs, new fs_1.NodeFS(), "f");
285
+ }
286
+ }
287
+ exports.AtlaspackWorker = AtlaspackWorker;
288
+ _AtlaspackWorker_resolvers = new WeakMap(), _AtlaspackWorker_transformers = new WeakMap(), _AtlaspackWorker_fs = new WeakMap();
289
+ // Create napi worker and send it back to main thread
290
+ const worker = new AtlaspackWorker();
291
+ const napiWorker = napi.newNodejsWorker(worker);
292
+ worker_threads_1.parentPort?.postMessage(napiWorker);
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ERROR = exports.STARTUP = exports.OPTION_CHANGE = exports.ENV_CHANGE = exports.FILE_DELETE = exports.FILE_UPDATE = exports.FILE_CREATE = exports.INITIAL_BUILD = exports.VALID = exports.HASH_REF_REGEX = exports.HASH_REF_HASH_LEN = exports.HASH_REF_PREFIX = exports.ATLASPACK_VERSION = void 0;
4
+ const package_json_1 = require("../package.json");
5
+ exports.ATLASPACK_VERSION = package_json_1.version;
6
+ exports.HASH_REF_PREFIX = 'HASH_REF_';
7
+ exports.HASH_REF_HASH_LEN = 16;
8
+ exports.HASH_REF_REGEX = new RegExp(`${exports.HASH_REF_PREFIX}\\w{${exports.HASH_REF_HASH_LEN}}`, 'g');
9
+ exports.VALID = 0;
10
+ exports.INITIAL_BUILD = 1 << 0;
11
+ exports.FILE_CREATE = 1 << 1;
12
+ exports.FILE_UPDATE = 1 << 2;
13
+ exports.FILE_DELETE = 1 << 3;
14
+ exports.ENV_CHANGE = 1 << 4;
15
+ exports.OPTION_CHANGE = 1 << 5;
16
+ exports.STARTUP = 1 << 6;
17
+ exports.ERROR = 1 << 7;