@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,142 @@
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
+ const stream_1 = require("stream");
7
+ const build_cache_1 = require("@atlaspack/build-cache");
8
+ const utils_1 = require("@atlaspack/utils");
9
+ const source_map_1 = __importDefault(require("@parcel/source-map"));
10
+ const assetUtils_1 = require("./assetUtils");
11
+ class CommittedAsset {
12
+ constructor(value, options) {
13
+ this.value = value;
14
+ this.key = this.value.contentKey;
15
+ this.options = options;
16
+ }
17
+ getContent() {
18
+ if (this.content == null) {
19
+ if (this.key != null) {
20
+ if (this.value.isLargeBlob) {
21
+ return this.options.cache.getStream(this.key);
22
+ }
23
+ else {
24
+ return this.options.cache.getBlob(this.key);
25
+ }
26
+ }
27
+ else if (this.value.astKey != null) {
28
+ return (0, utils_1.streamFromPromise)((0, assetUtils_1.generateFromAST)(this).then(({ content }) => {
29
+ if (!(content instanceof stream_1.Readable)) {
30
+ this.content = Promise.resolve(content);
31
+ }
32
+ return content;
33
+ }));
34
+ }
35
+ else {
36
+ throw new Error('Asset has no content');
37
+ }
38
+ }
39
+ return this.content;
40
+ }
41
+ async getCode() {
42
+ let content;
43
+ if (this.content == null && this.key != null) {
44
+ this.content = this.options.cache.getBlob(this.key);
45
+ content = await this.content;
46
+ }
47
+ else {
48
+ content = await this.getContent();
49
+ }
50
+ if (typeof content === 'string' || content instanceof Buffer) {
51
+ return content.toString();
52
+ }
53
+ else if (content != null) {
54
+ // @ts-expect-error TS2345
55
+ this.content = (0, utils_1.bufferStream)(content);
56
+ return (await this.content).toString();
57
+ }
58
+ return '';
59
+ }
60
+ async getBuffer() {
61
+ let content = await this.getContent();
62
+ if (content == null) {
63
+ return Buffer.alloc(0);
64
+ }
65
+ else if (typeof content === 'string' || content instanceof Buffer) {
66
+ return Buffer.from(content);
67
+ }
68
+ // @ts-expect-error TS2345
69
+ this.content = (0, utils_1.bufferStream)(content);
70
+ // @ts-expect-error TS2322
71
+ return this.content;
72
+ }
73
+ getStream() {
74
+ let content = this.getContent();
75
+ return content instanceof Promise
76
+ ? (0, utils_1.streamFromPromise)(content)
77
+ : (0, utils_1.blobToStream)(content);
78
+ }
79
+ getMapBuffer() {
80
+ let mapKey = this.value.mapKey;
81
+ if (mapKey != null && this.mapBuffer == null) {
82
+ this.mapBuffer = (async () => {
83
+ try {
84
+ // Handle v3 assets that were processed by the native asset graph code (i.e. not runtime
85
+ // or helper assets)
86
+ if (this.options.featureFlags.atlaspackV3 &&
87
+ this.value.meta.isV3 === true) {
88
+ let buffer = await this.options.cache.getBuffer(mapKey);
89
+ if (!buffer) {
90
+ return buffer;
91
+ }
92
+ // We make the conversion from json to buffer here, since both js packagers lazily
93
+ // instantiate a sourcemap from the map buffer. This ensures we do not have to modify
94
+ // the packagers in any significant way. Additionally, storing the SourceMap objects
95
+ // upfront in these packagers appears to make larger builds more prone to failing.
96
+ let sourceMap = new source_map_1.default(this.options.projectRoot);
97
+ sourceMap.addVLQMap(JSON.parse(buffer.toString()));
98
+ return sourceMap.toBuffer();
99
+ }
100
+ return await this.options.cache.getBlob(mapKey);
101
+ }
102
+ catch (err) {
103
+ if (err.code === 'ENOENT' && this.value.astKey != null) {
104
+ return (await (0, assetUtils_1.generateFromAST)(this)).map?.toBuffer();
105
+ }
106
+ else {
107
+ throw err;
108
+ }
109
+ }
110
+ })();
111
+ }
112
+ // @ts-expect-error TS2322
113
+ return this.mapBuffer ?? Promise.resolve();
114
+ }
115
+ getMap() {
116
+ if (this.map == null) {
117
+ this.map = (async () => {
118
+ let mapBuffer = await this.getMapBuffer();
119
+ if (mapBuffer) {
120
+ // Get sourcemap from flatbuffer
121
+ return new source_map_1.default(this.options.projectRoot, mapBuffer);
122
+ }
123
+ })();
124
+ }
125
+ return this.map;
126
+ }
127
+ getAST() {
128
+ if (this.value.astKey == null) {
129
+ return Promise.resolve(null);
130
+ }
131
+ if (this.ast == null) {
132
+ this.ast = this.options.cache
133
+ .getBlob(this.value.astKey)
134
+ .then((serializedAst) => (0, build_cache_1.deserializeRaw)(serializedAst));
135
+ }
136
+ return this.ast;
137
+ }
138
+ getDependencies() {
139
+ return Array.from(this.value.dependencies.values());
140
+ }
141
+ }
142
+ exports.default = CommittedAsset;
@@ -0,0 +1,125 @@
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.createDependencyId = createDependencyId;
7
+ exports.createDependency = createDependency;
8
+ exports.mergeDependencies = mergeDependencies;
9
+ const rust_1 = require("@atlaspack/rust");
10
+ const types_1 = require("./types");
11
+ const utils_1 = require("./utils");
12
+ const projectPath_1 = require("./projectPath");
13
+ const assert_1 = __importDefault(require("assert"));
14
+ const IdentifierRegistry_1 = require("./IdentifierRegistry");
15
+ const EnvironmentManager_1 = require("./EnvironmentManager");
16
+ function createDependencyId({ sourceAssetId, specifier, env, target, pipeline, specifierType, bundleBehavior, priority, packageConditions, }) {
17
+ (0, assert_1.default)(typeof specifierType === 'string');
18
+ (0, assert_1.default)(typeof priority === 'string' || priority == null);
19
+ const params = {
20
+ sourceAssetId,
21
+ specifier,
22
+ environmentId: (0, EnvironmentManager_1.toEnvironmentId)(env),
23
+ target: target != null
24
+ ? {
25
+ ...target,
26
+ env: (0, EnvironmentManager_1.fromEnvironmentId)(target.env),
27
+ }
28
+ : null,
29
+ pipeline,
30
+ specifierType: types_1.SpecifierType[specifierType],
31
+ bundleBehavior,
32
+ priority: priority ? types_1.Priority[priority] : types_1.Priority.sync,
33
+ packageConditions,
34
+ };
35
+ const id = (0, rust_1.createDependencyId)(params);
36
+ IdentifierRegistry_1.identifierRegistry.addIdentifier('dependency', id, params);
37
+ return id;
38
+ }
39
+ function createDependency(projectRoot, opts) {
40
+ let id = opts.id ||
41
+ createDependencyId({
42
+ bundleBehavior: opts.bundleBehavior,
43
+ env: opts.env,
44
+ packageConditions: opts.packageConditions,
45
+ pipeline: opts.pipeline,
46
+ priority: opts.priority,
47
+ sourceAssetId: opts.sourceAssetId,
48
+ specifier: opts.specifier,
49
+ specifierType: opts.specifierType,
50
+ target: opts.target,
51
+ });
52
+ let dep = {
53
+ id,
54
+ specifier: opts.specifier,
55
+ specifierType: types_1.SpecifierType[opts.specifierType],
56
+ priority: types_1.Priority[opts.priority ?? 'sync'],
57
+ needsStableName: opts.needsStableName ?? false,
58
+ bundleBehavior: opts.bundleBehavior
59
+ ? types_1.BundleBehavior[opts.bundleBehavior]
60
+ : null,
61
+ isEntry: opts.isEntry ?? false,
62
+ isOptional: opts.isOptional ?? false,
63
+ loc: (0, utils_1.toInternalSourceLocation)(projectRoot, opts.loc),
64
+ env: opts.env,
65
+ meta: opts.meta || {},
66
+ target: opts.target,
67
+ sourceAssetId: opts.sourceAssetId,
68
+ sourcePath: (0, projectPath_1.toProjectPath)(projectRoot, opts.sourcePath),
69
+ resolveFrom: (0, projectPath_1.toProjectPath)(projectRoot, opts.resolveFrom),
70
+ range: opts.range,
71
+ symbols: opts.symbols &&
72
+ new Map([...opts.symbols].map(([k, v]) => [
73
+ k,
74
+ {
75
+ local: v.local,
76
+ meta: v.meta,
77
+ isWeak: v.isWeak,
78
+ loc: (0, utils_1.toInternalSourceLocation)(projectRoot, v.loc),
79
+ },
80
+ ])),
81
+ pipeline: opts.pipeline,
82
+ };
83
+ if (opts.packageConditions) {
84
+ convertConditions(opts.packageConditions, dep);
85
+ }
86
+ return dep;
87
+ }
88
+ function mergeDependencies(a, b) {
89
+ let { meta, symbols, needsStableName, isEntry, isOptional, ...other } = b;
90
+ Object.assign(a, other);
91
+ Object.assign(a.meta, meta);
92
+ if (a.symbols && symbols) {
93
+ for (let [k, v] of symbols) {
94
+ a.symbols.set(k, v);
95
+ }
96
+ }
97
+ if (needsStableName)
98
+ a.needsStableName = true;
99
+ if (isEntry)
100
+ a.isEntry = true;
101
+ if (!isOptional)
102
+ a.isOptional = false;
103
+ }
104
+ function convertConditions(conditions, dep) {
105
+ // Store common package conditions as bit flags to reduce size.
106
+ // Custom conditions are stored as strings.
107
+ let packageConditions = 0;
108
+ let customConditions = [];
109
+ for (let condition of conditions) {
110
+ // @ts-expect-error TS7053
111
+ if (types_1.ExportsCondition[condition]) {
112
+ // @ts-expect-error TS7053
113
+ packageConditions |= types_1.ExportsCondition[condition];
114
+ }
115
+ else {
116
+ customConditions.push(condition);
117
+ }
118
+ }
119
+ if (packageConditions) {
120
+ dep.packageConditions = packageConditions;
121
+ }
122
+ if (customConditions.length) {
123
+ dep.customPackageConditions = customConditions;
124
+ }
125
+ }
@@ -0,0 +1,132 @@
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.createEnvironment = createEnvironment;
7
+ exports.mergeEnvironments = mergeEnvironments;
8
+ exports.getEnvironmentHash = getEnvironmentHash;
9
+ const rust_1 = require("@atlaspack/rust");
10
+ const utils_1 = require("./utils");
11
+ const Environment_1 = __importDefault(require("./public/Environment"));
12
+ const Environment_2 = require("./public/Environment");
13
+ const IdentifierRegistry_1 = require("./IdentifierRegistry");
14
+ const EnvironmentManager_1 = require("./EnvironmentManager");
15
+ const DEFAULT_ENGINES = {
16
+ browsers: ['> 0.25%'],
17
+ node: '>= 8.0.0',
18
+ };
19
+ function createEnvironment({ context, engines, includeNodeModules, outputFormat, sourceType = 'module', shouldOptimize = false, isLibrary = false, shouldScopeHoist = false, sourceMap, unstableSingleFileOutput = false, loc, customEnv, } = {
20
+ /*::...null*/
21
+ }) {
22
+ if (context == null) {
23
+ if (engines?.node) {
24
+ context = 'node';
25
+ }
26
+ else if (engines?.browsers) {
27
+ context = 'browser';
28
+ }
29
+ else {
30
+ context = 'browser';
31
+ }
32
+ }
33
+ if (engines == null) {
34
+ switch (context) {
35
+ case 'node':
36
+ case 'electron-main':
37
+ engines = {
38
+ node: DEFAULT_ENGINES.node,
39
+ };
40
+ break;
41
+ case 'browser':
42
+ case 'web-worker':
43
+ case 'service-worker':
44
+ case 'tesseract':
45
+ case 'electron-renderer':
46
+ engines = {
47
+ // @ts-expect-error TS2322
48
+ browsers: DEFAULT_ENGINES.browsers,
49
+ };
50
+ break;
51
+ default:
52
+ engines = {};
53
+ }
54
+ }
55
+ if (includeNodeModules == null) {
56
+ switch (context) {
57
+ case 'node':
58
+ case 'electron-main':
59
+ case 'electron-renderer':
60
+ includeNodeModules = false;
61
+ break;
62
+ case 'browser':
63
+ case 'web-worker':
64
+ case 'service-worker':
65
+ case 'tesseract':
66
+ default:
67
+ includeNodeModules = true;
68
+ break;
69
+ }
70
+ }
71
+ if (outputFormat == null) {
72
+ switch (context) {
73
+ case 'node':
74
+ case 'electron-main':
75
+ case 'electron-renderer':
76
+ outputFormat = 'commonjs';
77
+ break;
78
+ default:
79
+ outputFormat = 'global';
80
+ break;
81
+ }
82
+ }
83
+ let res = {
84
+ id: '',
85
+ context,
86
+ // @ts-expect-error TS2322
87
+ engines,
88
+ includeNodeModules,
89
+ outputFormat,
90
+ sourceType,
91
+ isLibrary,
92
+ shouldOptimize,
93
+ shouldScopeHoist,
94
+ sourceMap,
95
+ unstableSingleFileOutput,
96
+ loc,
97
+ customEnv,
98
+ };
99
+ res.id = getEnvironmentHash(res);
100
+ return (0, EnvironmentManager_1.toEnvironmentRef)(Object.freeze(res));
101
+ }
102
+ function mergeEnvironments(projectRoot, a, b) {
103
+ // If merging the same object, avoid copying.
104
+ if (a === b || !b) {
105
+ return (0, EnvironmentManager_1.toEnvironmentRef)(a);
106
+ }
107
+ if (b instanceof Environment_1.default) {
108
+ return (0, EnvironmentManager_1.toEnvironmentRef)((0, Environment_2.environmentToInternalEnvironment)(b));
109
+ }
110
+ return createEnvironment({
111
+ ...a,
112
+ ...b,
113
+ loc: b.loc ? (0, utils_1.toInternalSourceLocation)(projectRoot, b.loc) : a.loc,
114
+ });
115
+ }
116
+ function getEnvironmentHash(env) {
117
+ const data = {
118
+ context: env.context,
119
+ engines: env.engines,
120
+ includeNodeModules: env.includeNodeModules,
121
+ outputFormat: env.outputFormat,
122
+ sourceType: env.sourceType,
123
+ isLibrary: env.isLibrary,
124
+ shouldOptimize: env.shouldOptimize,
125
+ shouldScopeHoist: env.shouldScopeHoist,
126
+ sourceMap: env.sourceMap,
127
+ customEnv: env.customEnv,
128
+ };
129
+ const id = (0, rust_1.createEnvironmentId)(data);
130
+ IdentifierRegistry_1.identifierRegistry.addIdentifier('environment', id, data);
131
+ return id;
132
+ }
@@ -0,0 +1,108 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.toEnvironmentRef = toEnvironmentRef;
4
+ exports.toEnvironmentId = toEnvironmentId;
5
+ exports.fromEnvironmentId = fromEnvironmentId;
6
+ exports.writeEnvironmentsToCache = writeEnvironmentsToCache;
7
+ exports.loadEnvironmentsFromCache = loadEnvironmentsFromCache;
8
+ const rust_1 = require("@atlaspack/rust");
9
+ const feature_flags_1 = require("@atlaspack/feature-flags");
10
+ const logger_1 = require("@atlaspack/logger");
11
+ const constants_1 = require("./constants");
12
+ const localEnvironmentCache = new Map();
13
+ /**
14
+ * Convert environment to a ref.
15
+ * This is what we should be using to store environments.
16
+ */
17
+ function toEnvironmentRef(env) {
18
+ if (!(0, feature_flags_1.getFeatureFlag)('environmentDeduplication')) {
19
+ return env;
20
+ }
21
+ const id = toEnvironmentId(env);
22
+ return id;
23
+ }
24
+ /**
25
+ * Convert environment to a string ID
26
+ */
27
+ function toEnvironmentId(
28
+ /**
29
+ * Redundant type during roll-out
30
+ */
31
+ env) {
32
+ if (!(0, feature_flags_1.getFeatureFlag)('environmentDeduplication')) {
33
+ return typeof env === 'string' ? env : env.id;
34
+ }
35
+ if (typeof env === 'string') {
36
+ return env;
37
+ }
38
+ (0, rust_1.addEnvironment)(env);
39
+ return env.id;
40
+ }
41
+ function fromEnvironmentId(id) {
42
+ if (!(0, feature_flags_1.getFeatureFlag)('environmentDeduplication')) {
43
+ if (typeof id === 'string') {
44
+ throw new Error('This should never happen when environmentDeduplication feature-flag is off');
45
+ }
46
+ else {
47
+ return id;
48
+ }
49
+ }
50
+ if (typeof id !== 'string') {
51
+ return id;
52
+ }
53
+ const localEnv = localEnvironmentCache.get(id);
54
+ if (localEnv) {
55
+ return localEnv;
56
+ }
57
+ const env = Object.freeze((0, rust_1.getEnvironment)(id));
58
+ // @ts-expect-error TS2345
59
+ localEnvironmentCache.set(id, env);
60
+ // @ts-expect-error TS2322
61
+ return env;
62
+ }
63
+ /**
64
+ * Writes all environments and their IDs to the cache
65
+ * @param {Cache} cache
66
+ * @returns {Promise<void>}
67
+ */
68
+ async function writeEnvironmentsToCache(cache) {
69
+ const environments = (0, rust_1.getAllEnvironments)();
70
+ const environmentIds = new Set();
71
+ // Store each environment individually
72
+ for (const env of environments) {
73
+ // @ts-expect-error TS18046
74
+ environmentIds.add(env.id);
75
+ // @ts-expect-error TS18046
76
+ const envKey = `Environment/${constants_1.ATLASPACK_VERSION}/${env.id}`;
77
+ await (0, logger_1.instrument)(`RequestTracker::writeToCache::cache.put(${envKey})`, async () => {
78
+ await cache.set(envKey, env);
79
+ });
80
+ }
81
+ // Store the list of environment IDs
82
+ await (0, logger_1.instrument)(`RequestTracker::writeToCache::cache.put(${`EnvironmentManager/${constants_1.ATLASPACK_VERSION}`})`, async () => {
83
+ await cache.set(`EnvironmentManager/${constants_1.ATLASPACK_VERSION}`, Array.from(environmentIds));
84
+ });
85
+ }
86
+ /**
87
+ * Loads all environments and their IDs from the cache
88
+ * @param {Cache} cache
89
+ * @returns {Promise<void>}
90
+ */
91
+ async function loadEnvironmentsFromCache(cache) {
92
+ const cachedEnvIds = await cache.get(`EnvironmentManager/${constants_1.ATLASPACK_VERSION}`);
93
+ if (cachedEnvIds == null) {
94
+ return;
95
+ }
96
+ const environments = [];
97
+ // @ts-expect-error TS2488
98
+ for (const envId of cachedEnvIds) {
99
+ const envKey = `Environment/${constants_1.ATLASPACK_VERSION}/${envId}`;
100
+ const cachedEnv = await cache.get(envKey);
101
+ if (cachedEnv != null) {
102
+ environments.push(cachedEnv);
103
+ }
104
+ }
105
+ if (environments.length > 0) {
106
+ (0, rust_1.setAllEnvironments)(environments);
107
+ }
108
+ }
@@ -0,0 +1,38 @@
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 _IdentifierRegistry_enabled, _IdentifierRegistry_createdDirectory;
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.identifierRegistry = exports.IdentifierRegistry = void 0;
19
+ const fs_1 = __importDefault(require("fs"));
20
+ class IdentifierRegistry {
21
+ constructor(enabled) {
22
+ _IdentifierRegistry_enabled.set(this, void 0);
23
+ _IdentifierRegistry_createdDirectory.set(this, false);
24
+ __classPrivateFieldSet(this, _IdentifierRegistry_enabled, enabled, "f");
25
+ }
26
+ addIdentifier(type, identifier, data) {
27
+ if (__classPrivateFieldGet(this, _IdentifierRegistry_enabled, "f")) {
28
+ if (!__classPrivateFieldGet(this, _IdentifierRegistry_createdDirectory, "f")) {
29
+ fs_1.default.mkdirSync('./.atlaspack', { recursive: true });
30
+ __classPrivateFieldSet(this, _IdentifierRegistry_createdDirectory, true, "f");
31
+ }
32
+ fs_1.default.appendFile('./.atlaspack/atlaspack-identifiers.txt', `${type} ${identifier} ${JSON.stringify(data)}\n`, () => { });
33
+ }
34
+ }
35
+ }
36
+ exports.IdentifierRegistry = IdentifierRegistry;
37
+ _IdentifierRegistry_enabled = new WeakMap(), _IdentifierRegistry_createdDirectory = new WeakMap();
38
+ exports.identifierRegistry = new IdentifierRegistry(process.env.ATLASPACK_IDENTIFIER_DEBUG === 'true');
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createConfig = createConfig;
4
+ const projectPath_1 = require("./projectPath");
5
+ const Environment_1 = require("./Environment");
6
+ const rust_1 = require("@atlaspack/rust");
7
+ const IdentifierRegistry_1 = require("./IdentifierRegistry");
8
+ const EnvironmentManager_1 = require("./EnvironmentManager");
9
+ function createConfig({ plugin, isSource, searchPath, env, result, invalidateOnFileChange, invalidateOnConfigKeyChange, invalidateOnFileCreate, invalidateOnEnvChange, invalidateOnOptionChange, devDeps, invalidateOnStartup, invalidateOnBuild, }) {
10
+ let environment = env ?? (0, Environment_1.createEnvironment)();
11
+ const configId = (0, rust_1.hashString)(plugin +
12
+ (0, projectPath_1.fromProjectPathRelative)(searchPath) +
13
+ (0, EnvironmentManager_1.toEnvironmentId)(environment) +
14
+ String(isSource));
15
+ IdentifierRegistry_1.identifierRegistry.addIdentifier('config_request', configId, {
16
+ plugin,
17
+ searchPath,
18
+ environmentId: (0, EnvironmentManager_1.toEnvironmentId)(environment),
19
+ isSource,
20
+ });
21
+ return {
22
+ id: configId,
23
+ isSource: isSource ?? false,
24
+ searchPath,
25
+ env: environment,
26
+ result: result ?? null,
27
+ cacheKey: null,
28
+ invalidateOnFileChange: invalidateOnFileChange ?? new Set(),
29
+ invalidateOnConfigKeyChange: invalidateOnConfigKeyChange ?? [],
30
+ invalidateOnFileCreate: invalidateOnFileCreate ?? [],
31
+ invalidateOnEnvChange: invalidateOnEnvChange ?? new Set(),
32
+ invalidateOnOptionChange: invalidateOnOptionChange ?? new Set(),
33
+ devDeps: devDeps ?? [],
34
+ invalidateOnStartup: invalidateOnStartup ?? false,
35
+ invalidateOnBuild: invalidateOnBuild ?? false,
36
+ };
37
+ }