@atlaspack/core 2.24.0 → 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.
- package/CHANGELOG.md +26 -0
- package/LICENSE +201 -0
- package/dist/AssetGraph.js +591 -0
- package/dist/Atlaspack.js +656 -0
- package/dist/AtlaspackConfig.js +324 -0
- package/dist/AtlaspackConfig.schema.js +108 -0
- package/dist/BundleGraph.js +1628 -0
- package/dist/CommittedAsset.js +142 -0
- package/dist/Dependency.js +125 -0
- package/dist/Environment.js +132 -0
- package/dist/EnvironmentManager.js +108 -0
- package/dist/IdentifierRegistry.js +38 -0
- package/dist/InternalConfig.js +37 -0
- package/dist/PackagerRunner.js +531 -0
- package/dist/ReporterRunner.js +151 -0
- package/dist/RequestTracker.js +1368 -0
- package/dist/SymbolPropagation.js +620 -0
- package/dist/TargetDescriptor.schema.js +143 -0
- package/dist/Transformation.js +487 -0
- package/dist/UncommittedAsset.js +315 -0
- package/dist/Validation.js +196 -0
- package/dist/applyRuntimes.js +305 -0
- package/dist/assetUtils.js +168 -0
- package/dist/atlaspack-v3/AtlaspackV3.js +70 -0
- package/dist/atlaspack-v3/NapiWorkerPool.js +57 -0
- package/dist/atlaspack-v3/fs.js +52 -0
- package/dist/atlaspack-v3/index.js +25 -0
- package/dist/atlaspack-v3/jsCallable.js +16 -0
- package/dist/atlaspack-v3/worker/compat/asset-symbols.js +190 -0
- package/dist/atlaspack-v3/worker/compat/bitflags.js +94 -0
- package/dist/atlaspack-v3/worker/compat/dependency.js +43 -0
- package/dist/atlaspack-v3/worker/compat/environment.js +57 -0
- package/dist/atlaspack-v3/worker/compat/index.js +25 -0
- package/dist/atlaspack-v3/worker/compat/mutable-asset.js +152 -0
- package/dist/atlaspack-v3/worker/compat/plugin-config.js +76 -0
- package/dist/atlaspack-v3/worker/compat/plugin-logger.js +26 -0
- package/dist/atlaspack-v3/worker/compat/plugin-options.js +122 -0
- package/dist/atlaspack-v3/worker/compat/plugin-tracer.js +10 -0
- package/dist/atlaspack-v3/worker/compat/target.js +14 -0
- package/dist/atlaspack-v3/worker/worker.js +292 -0
- package/dist/constants.js +17 -0
- package/dist/dumpGraphToGraphViz.js +281 -0
- package/dist/index.js +62 -0
- package/dist/loadAtlaspackPlugin.js +128 -0
- package/dist/loadDotEnv.js +41 -0
- package/dist/projectPath.js +83 -0
- package/dist/public/Asset.js +279 -0
- package/dist/public/Bundle.js +224 -0
- package/dist/public/BundleGraph.js +359 -0
- package/dist/public/BundleGroup.js +53 -0
- package/dist/public/Config.js +286 -0
- package/dist/public/Dependency.js +138 -0
- package/dist/public/Environment.js +278 -0
- package/dist/public/MutableBundleGraph.js +277 -0
- package/dist/public/PluginOptions.js +80 -0
- package/dist/public/Symbols.js +248 -0
- package/dist/public/Target.js +69 -0
- package/dist/registerCoreWithSerializer.js +38 -0
- package/dist/requests/AssetGraphRequest.js +429 -0
- package/dist/requests/AssetGraphRequestRust.js +246 -0
- package/dist/requests/AssetRequest.js +130 -0
- package/dist/requests/AtlaspackBuildRequest.js +60 -0
- package/dist/requests/AtlaspackConfigRequest.js +490 -0
- package/dist/requests/BundleGraphRequest.js +441 -0
- package/dist/requests/ConfigRequest.js +222 -0
- package/dist/requests/DevDepRequest.js +204 -0
- package/dist/requests/EntryRequest.js +314 -0
- package/dist/requests/PackageRequest.js +65 -0
- package/dist/requests/PathRequest.js +349 -0
- package/dist/requests/TargetRequest.js +1310 -0
- package/dist/requests/ValidationRequest.js +49 -0
- package/dist/requests/WriteBundleRequest.js +254 -0
- package/dist/requests/WriteBundlesRequest.js +165 -0
- package/dist/requests/asset-graph-diff.js +126 -0
- package/dist/requests/asset-graph-dot.js +131 -0
- package/dist/resolveOptions.js +268 -0
- package/dist/rustWorkerThreadDylibHack.js +19 -0
- package/dist/serializerCore.browser.js +43 -0
- package/dist/summarizeRequest.js +39 -0
- package/dist/types.js +31 -0
- package/dist/utils.js +172 -0
- package/dist/worker.js +130 -0
- package/lib/AssetGraph.js +1 -0
- package/lib/atlaspack-v3/AtlaspackV3.js +7 -3
- package/lib/requests/AssetGraphRequestRust.js +1 -1
- package/lib/types/atlaspack-v3/AtlaspackV3.d.ts +1 -1
- package/package.json +22 -22
- package/src/AssetGraph.ts +1 -0
- package/src/atlaspack-v3/AtlaspackV3.ts +12 -3
- package/src/requests/AssetGraphRequestRust.ts +1 -1
- package/tsconfig.json +55 -2
- package/tsconfig.tsbuildinfo +1 -0
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.COMMON_TARGET_DESCRIPTOR_SCHEMA = exports.DESCRIPTOR_SCHEMA = exports.PACKAGE_DESCRIPTOR_SCHEMA = exports.ENGINES_SCHEMA = void 0;
|
|
4
|
+
exports.ENGINES_SCHEMA = {
|
|
5
|
+
type: 'object',
|
|
6
|
+
properties: {
|
|
7
|
+
browsers: {
|
|
8
|
+
oneOf: [
|
|
9
|
+
{
|
|
10
|
+
type: 'array',
|
|
11
|
+
items: {
|
|
12
|
+
type: 'string',
|
|
13
|
+
},
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
type: 'string',
|
|
17
|
+
},
|
|
18
|
+
],
|
|
19
|
+
},
|
|
20
|
+
},
|
|
21
|
+
__forbiddenProperties: ['browser'],
|
|
22
|
+
additionalProperties: {
|
|
23
|
+
type: 'string',
|
|
24
|
+
},
|
|
25
|
+
};
|
|
26
|
+
exports.PACKAGE_DESCRIPTOR_SCHEMA = {
|
|
27
|
+
type: 'object',
|
|
28
|
+
properties: {
|
|
29
|
+
context: {
|
|
30
|
+
type: 'string',
|
|
31
|
+
enum: [
|
|
32
|
+
'node',
|
|
33
|
+
'browser',
|
|
34
|
+
'web-worker',
|
|
35
|
+
'electron-main',
|
|
36
|
+
'electron-renderer',
|
|
37
|
+
'service-worker',
|
|
38
|
+
'tesseract',
|
|
39
|
+
],
|
|
40
|
+
},
|
|
41
|
+
includeNodeModules: {
|
|
42
|
+
oneOf: [
|
|
43
|
+
{
|
|
44
|
+
type: 'boolean',
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
type: 'array',
|
|
48
|
+
items: {
|
|
49
|
+
type: 'string',
|
|
50
|
+
__type: 'a wildcard or filepath',
|
|
51
|
+
},
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
type: 'object',
|
|
55
|
+
properties: {},
|
|
56
|
+
additionalProperties: {
|
|
57
|
+
type: 'boolean',
|
|
58
|
+
},
|
|
59
|
+
},
|
|
60
|
+
],
|
|
61
|
+
},
|
|
62
|
+
outputFormat: {
|
|
63
|
+
type: 'string',
|
|
64
|
+
enum: ['global', 'esmodule', 'commonjs'],
|
|
65
|
+
},
|
|
66
|
+
distDir: {
|
|
67
|
+
type: 'string',
|
|
68
|
+
},
|
|
69
|
+
publicUrl: {
|
|
70
|
+
type: 'string',
|
|
71
|
+
},
|
|
72
|
+
isLibrary: {
|
|
73
|
+
type: 'boolean',
|
|
74
|
+
},
|
|
75
|
+
source: {
|
|
76
|
+
oneOf: [
|
|
77
|
+
{
|
|
78
|
+
type: 'string',
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
type: 'array',
|
|
82
|
+
items: { type: 'string' },
|
|
83
|
+
},
|
|
84
|
+
],
|
|
85
|
+
},
|
|
86
|
+
sourceMap: {
|
|
87
|
+
oneOf: [
|
|
88
|
+
{
|
|
89
|
+
type: 'boolean',
|
|
90
|
+
},
|
|
91
|
+
{
|
|
92
|
+
type: 'object',
|
|
93
|
+
properties: {
|
|
94
|
+
inlineSources: {
|
|
95
|
+
type: 'boolean',
|
|
96
|
+
},
|
|
97
|
+
sourceRoot: {
|
|
98
|
+
type: 'string',
|
|
99
|
+
},
|
|
100
|
+
inline: {
|
|
101
|
+
type: 'boolean',
|
|
102
|
+
},
|
|
103
|
+
},
|
|
104
|
+
additionalProperties: false,
|
|
105
|
+
},
|
|
106
|
+
],
|
|
107
|
+
},
|
|
108
|
+
engines: exports.ENGINES_SCHEMA,
|
|
109
|
+
optimize: {
|
|
110
|
+
type: 'boolean',
|
|
111
|
+
},
|
|
112
|
+
scopeHoist: {
|
|
113
|
+
type: 'boolean',
|
|
114
|
+
},
|
|
115
|
+
__unstable_singleFileOutput: {
|
|
116
|
+
type: 'boolean',
|
|
117
|
+
},
|
|
118
|
+
env: {
|
|
119
|
+
type: 'object',
|
|
120
|
+
additionalProperties: {
|
|
121
|
+
type: 'string',
|
|
122
|
+
},
|
|
123
|
+
},
|
|
124
|
+
},
|
|
125
|
+
additionalProperties: false,
|
|
126
|
+
};
|
|
127
|
+
exports.DESCRIPTOR_SCHEMA = {
|
|
128
|
+
...exports.PACKAGE_DESCRIPTOR_SCHEMA,
|
|
129
|
+
properties: {
|
|
130
|
+
...exports.PACKAGE_DESCRIPTOR_SCHEMA.properties,
|
|
131
|
+
distEntry: {
|
|
132
|
+
type: 'string',
|
|
133
|
+
},
|
|
134
|
+
},
|
|
135
|
+
};
|
|
136
|
+
exports.COMMON_TARGET_DESCRIPTOR_SCHEMA = {
|
|
137
|
+
oneOf: [
|
|
138
|
+
exports.PACKAGE_DESCRIPTOR_SCHEMA,
|
|
139
|
+
{
|
|
140
|
+
enum: [false],
|
|
141
|
+
},
|
|
142
|
+
],
|
|
143
|
+
};
|
|
@@ -0,0 +1,487 @@
|
|
|
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 __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
const path_1 = __importDefault(require("path"));
|
|
40
|
+
const stream_1 = require("stream");
|
|
41
|
+
const nullthrows_1 = __importDefault(require("nullthrows"));
|
|
42
|
+
const logger_1 = __importStar(require("@atlaspack/logger"));
|
|
43
|
+
const diagnostic_1 = __importStar(require("@atlaspack/diagnostic"));
|
|
44
|
+
const utils_1 = require("@atlaspack/utils");
|
|
45
|
+
const Dependency_1 = require("./Dependency");
|
|
46
|
+
// TODO: eventually call path request as sub requests
|
|
47
|
+
const PathRequest_1 = require("./requests/PathRequest");
|
|
48
|
+
const Asset_1 = require("./public/Asset");
|
|
49
|
+
const UncommittedAsset_1 = __importDefault(require("./UncommittedAsset"));
|
|
50
|
+
const assetUtils_1 = require("./assetUtils");
|
|
51
|
+
const summarizeRequest_1 = __importDefault(require("./summarizeRequest"));
|
|
52
|
+
const PluginOptions_1 = __importDefault(require("./public/PluginOptions"));
|
|
53
|
+
const utils_2 = require("./utils");
|
|
54
|
+
const InternalConfig_1 = require("./InternalConfig");
|
|
55
|
+
const ConfigRequest_1 = require("./requests/ConfigRequest");
|
|
56
|
+
const DevDepRequest_1 = require("./requests/DevDepRequest");
|
|
57
|
+
const projectPath_1 = require("./projectPath");
|
|
58
|
+
const utils_3 = require("./utils");
|
|
59
|
+
const assert_1 = __importDefault(require("assert"));
|
|
60
|
+
const profiler_1 = require("@atlaspack/profiler");
|
|
61
|
+
class Transformation {
|
|
62
|
+
constructor({ request, options, config, workerApi }) {
|
|
63
|
+
this.configs = new Map();
|
|
64
|
+
this.atlaspackConfig = config;
|
|
65
|
+
this.options = options;
|
|
66
|
+
this.request = request;
|
|
67
|
+
this.workerApi = workerApi;
|
|
68
|
+
this.invalidations = (0, utils_3.createInvalidations)();
|
|
69
|
+
this.devDepRequests = new Map();
|
|
70
|
+
this.pluginDevDeps = [];
|
|
71
|
+
this.resolverRunner = new PathRequest_1.ResolverRunner({
|
|
72
|
+
config,
|
|
73
|
+
options,
|
|
74
|
+
previousDevDeps: request.devDeps,
|
|
75
|
+
});
|
|
76
|
+
this.pluginOptions = new PluginOptions_1.default((0, utils_2.optionsProxy)(this.options, (option) => {
|
|
77
|
+
this.invalidations.invalidateOnOptionChange.add(option);
|
|
78
|
+
}, (devDep) => {
|
|
79
|
+
this.pluginDevDeps.push(devDep);
|
|
80
|
+
}));
|
|
81
|
+
}
|
|
82
|
+
async run() {
|
|
83
|
+
let asset = await this.loadAsset();
|
|
84
|
+
let existing;
|
|
85
|
+
if (!asset.mapBuffer && utils_1.SOURCEMAP_EXTENSIONS.has(asset.value.type)) {
|
|
86
|
+
// Load existing sourcemaps, this automatically runs the source contents extraction
|
|
87
|
+
try {
|
|
88
|
+
existing = await asset.loadExistingSourcemap();
|
|
89
|
+
}
|
|
90
|
+
catch (err) {
|
|
91
|
+
logger_1.default.verbose([
|
|
92
|
+
{
|
|
93
|
+
origin: '@atlaspack/core',
|
|
94
|
+
message: (0, diagnostic_1.md) `Could not load existing source map for ${(0, projectPath_1.fromProjectPathRelative)(asset.value.filePath)}`,
|
|
95
|
+
},
|
|
96
|
+
{
|
|
97
|
+
origin: '@atlaspack/core',
|
|
98
|
+
message: (0, diagnostic_1.escapeMarkdown)(err.message),
|
|
99
|
+
},
|
|
100
|
+
]);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
if (existing == null &&
|
|
104
|
+
// Don't buffer an entire stream into memory since it may not need sourceContent,
|
|
105
|
+
// e.g. large binary files
|
|
106
|
+
!(asset.content instanceof stream_1.Readable)) {
|
|
107
|
+
// If no existing sourcemap was found, initialize asset.sourceContent
|
|
108
|
+
// with the original contents. This will be used when the transformer
|
|
109
|
+
// calls setMap to ensure the source content is in the sourcemap.
|
|
110
|
+
asset.sourceContent = await asset.getCode();
|
|
111
|
+
}
|
|
112
|
+
(0, DevDepRequest_1.invalidateDevDeps)(this.request.invalidDevDeps, this.options, this.atlaspackConfig);
|
|
113
|
+
let pipeline = await this.loadPipeline(
|
|
114
|
+
// @ts-expect-error TS2345
|
|
115
|
+
this.request.filePath, asset.value.isSource, asset.value.pipeline);
|
|
116
|
+
let assets, error;
|
|
117
|
+
try {
|
|
118
|
+
let results = await this.runPipelines(pipeline, asset);
|
|
119
|
+
await Promise.all(results.map((asset) => asset.commit()));
|
|
120
|
+
assets = results.map((a) => a.value);
|
|
121
|
+
}
|
|
122
|
+
catch (e) {
|
|
123
|
+
error = e;
|
|
124
|
+
}
|
|
125
|
+
let configRequests = (0, ConfigRequest_1.getConfigRequests)([
|
|
126
|
+
...this.configs.values(),
|
|
127
|
+
...this.resolverRunner.configs.values(),
|
|
128
|
+
]);
|
|
129
|
+
let devDepRequests = (0, DevDepRequest_1.getWorkerDevDepRequests)([
|
|
130
|
+
...this.devDepRequests.values(),
|
|
131
|
+
...this.resolverRunner.devDepRequests.values(),
|
|
132
|
+
]);
|
|
133
|
+
return {
|
|
134
|
+
// @ts-expect-error TS2353
|
|
135
|
+
$$raw: true,
|
|
136
|
+
assets,
|
|
137
|
+
configRequests,
|
|
138
|
+
// When throwing an error, this (de)serialization is done automatically by the WorkerFarm
|
|
139
|
+
error: error ? (0, diagnostic_1.anyToDiagnostic)(error) : undefined,
|
|
140
|
+
invalidations: this.invalidations,
|
|
141
|
+
devDepRequests,
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
async loadAsset() {
|
|
145
|
+
let { filePath, env, code, pipeline, isSource: isSourceOverride, sideEffects, query, } = this.request;
|
|
146
|
+
let { content, size, isSource: summarizedIsSource, } = await (0, summarizeRequest_1.default)(this.options.inputFS, {
|
|
147
|
+
// @ts-expect-error TS2322
|
|
148
|
+
filePath: (0, projectPath_1.fromProjectPath)(this.options.projectRoot, filePath),
|
|
149
|
+
code,
|
|
150
|
+
});
|
|
151
|
+
// Prefer `isSource` originating from the AssetRequest.
|
|
152
|
+
let isSource = isSourceOverride ?? summarizedIsSource;
|
|
153
|
+
return new UncommittedAsset_1.default({
|
|
154
|
+
value: (0, assetUtils_1.createAsset)(this.options.projectRoot, {
|
|
155
|
+
code,
|
|
156
|
+
// @ts-expect-error TS2322
|
|
157
|
+
filePath,
|
|
158
|
+
isSource,
|
|
159
|
+
// @ts-expect-error TS2345
|
|
160
|
+
type: path_1.default.extname((0, projectPath_1.fromProjectPathRelative)(filePath)).slice(1),
|
|
161
|
+
pipeline,
|
|
162
|
+
// @ts-expect-error TS2322
|
|
163
|
+
env,
|
|
164
|
+
query,
|
|
165
|
+
stats: {
|
|
166
|
+
time: 0,
|
|
167
|
+
size,
|
|
168
|
+
},
|
|
169
|
+
sideEffects,
|
|
170
|
+
}),
|
|
171
|
+
options: this.options,
|
|
172
|
+
content,
|
|
173
|
+
invalidations: this.invalidations,
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
async runPipelines(pipeline, initialAsset) {
|
|
177
|
+
let initialType = initialAsset.value.type;
|
|
178
|
+
let assets;
|
|
179
|
+
try {
|
|
180
|
+
assets = await this.runPipeline(pipeline, initialAsset);
|
|
181
|
+
}
|
|
182
|
+
finally {
|
|
183
|
+
// Add dev dep requests for each transformer
|
|
184
|
+
for (let transformer of pipeline.transformers) {
|
|
185
|
+
await this.addDevDependency({
|
|
186
|
+
specifier: transformer.name,
|
|
187
|
+
resolveFrom: transformer.resolveFrom,
|
|
188
|
+
range: transformer.range,
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
// Add dev dep requests for dependencies of transformer plugins
|
|
192
|
+
// (via proxied packageManager.require calls).
|
|
193
|
+
for (let devDep of this.pluginDevDeps) {
|
|
194
|
+
await this.addDevDependency(devDep);
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
let finalAssets = [];
|
|
198
|
+
for (let asset of assets) {
|
|
199
|
+
let nextPipeline;
|
|
200
|
+
if (asset.value.type !== initialType) {
|
|
201
|
+
nextPipeline = await this.loadNextPipeline({
|
|
202
|
+
filePath: initialAsset.value.filePath,
|
|
203
|
+
isSource: asset.value.isSource,
|
|
204
|
+
newType: asset.value.type,
|
|
205
|
+
newPipeline: asset.value.pipeline,
|
|
206
|
+
currentPipeline: pipeline,
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
if (nextPipeline) {
|
|
210
|
+
let nextPipelineAssets = await this.runPipelines(nextPipeline, asset);
|
|
211
|
+
finalAssets = finalAssets.concat(nextPipelineAssets);
|
|
212
|
+
}
|
|
213
|
+
else {
|
|
214
|
+
finalAssets.push(asset);
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
if (!pipeline.postProcess) {
|
|
218
|
+
return finalAssets;
|
|
219
|
+
}
|
|
220
|
+
(0, assert_1.default)(pipeline.postProcess != null);
|
|
221
|
+
let processedFinalAssets = (await pipeline.postProcess(finalAssets)) ?? [];
|
|
222
|
+
return processedFinalAssets;
|
|
223
|
+
}
|
|
224
|
+
async addDevDependency(opts) {
|
|
225
|
+
let { specifier, resolveFrom, range } = opts;
|
|
226
|
+
let key = `${specifier}:${(0, projectPath_1.fromProjectPathRelative)(resolveFrom)}`;
|
|
227
|
+
if (this.devDepRequests.has(key)) {
|
|
228
|
+
return;
|
|
229
|
+
}
|
|
230
|
+
// Ensure that the package manager has an entry for this resolution.
|
|
231
|
+
try {
|
|
232
|
+
await this.options.packageManager.resolve(specifier, (0, projectPath_1.fromProjectPath)(this.options.projectRoot, opts.resolveFrom), {
|
|
233
|
+
range,
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
catch (err) {
|
|
237
|
+
// ignore
|
|
238
|
+
}
|
|
239
|
+
let devDepRequest = await (0, DevDepRequest_1.createDevDependency)(opts, this.request.devDeps, this.options);
|
|
240
|
+
this.devDepRequests.set(key, devDepRequest);
|
|
241
|
+
}
|
|
242
|
+
async runPipeline(pipeline, initialAsset) {
|
|
243
|
+
if (pipeline.transformers.length === 0) {
|
|
244
|
+
return [initialAsset];
|
|
245
|
+
}
|
|
246
|
+
let initialType = initialAsset.value.type;
|
|
247
|
+
let inputAssets = [initialAsset];
|
|
248
|
+
let resultingAssets = [];
|
|
249
|
+
let finalAssets = [];
|
|
250
|
+
for (let transformer of pipeline.transformers) {
|
|
251
|
+
resultingAssets = [];
|
|
252
|
+
for (let asset of inputAssets) {
|
|
253
|
+
if (asset.value.type !== initialType &&
|
|
254
|
+
(await this.loadNextPipeline({
|
|
255
|
+
filePath: initialAsset.value.filePath,
|
|
256
|
+
isSource: asset.value.isSource,
|
|
257
|
+
newType: asset.value.type,
|
|
258
|
+
newPipeline: asset.value.pipeline,
|
|
259
|
+
currentPipeline: pipeline,
|
|
260
|
+
}))) {
|
|
261
|
+
finalAssets.push(asset);
|
|
262
|
+
continue;
|
|
263
|
+
}
|
|
264
|
+
try {
|
|
265
|
+
const measurement = profiler_1.tracer.createMeasurement(transformer.name, 'transform', (0, projectPath_1.fromProjectPathRelative)(initialAsset.value.filePath));
|
|
266
|
+
let transformerResults = await this.runTransformer(pipeline, asset, transformer.plugin, transformer.name, transformer.config, transformer.configKeyPath, this.atlaspackConfig);
|
|
267
|
+
measurement && measurement.end();
|
|
268
|
+
for (let result of transformerResults) {
|
|
269
|
+
if (result instanceof UncommittedAsset_1.default) {
|
|
270
|
+
resultingAssets.push(result);
|
|
271
|
+
continue;
|
|
272
|
+
}
|
|
273
|
+
resultingAssets.push(asset.createChildAsset(result, transformer.name, this.atlaspackConfig.filePath, transformer.configKeyPath));
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
catch (e) {
|
|
277
|
+
let diagnostic = (0, diagnostic_1.errorToDiagnostic)(e, {
|
|
278
|
+
origin: transformer.name,
|
|
279
|
+
filePath: (0, projectPath_1.fromProjectPath)(this.options.projectRoot, asset.value.filePath),
|
|
280
|
+
});
|
|
281
|
+
// If this request is a virtual asset that might not exist on the filesystem,
|
|
282
|
+
// add the `code` property to each code frame in the diagnostics that match the
|
|
283
|
+
// request's filepath. This can't be done by the transformer because it might not
|
|
284
|
+
// have access to the original code (e.g. an inline script tag in HTML).
|
|
285
|
+
if (this.request.code != null) {
|
|
286
|
+
for (let d of diagnostic) {
|
|
287
|
+
if (d.codeFrames) {
|
|
288
|
+
for (let codeFrame of d.codeFrames) {
|
|
289
|
+
if (codeFrame.code == null &&
|
|
290
|
+
codeFrame.filePath === this.request.filePath) {
|
|
291
|
+
codeFrame.code = this.request.code;
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
throw new diagnostic_1.default({
|
|
298
|
+
diagnostic,
|
|
299
|
+
});
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
inputAssets = resultingAssets;
|
|
303
|
+
}
|
|
304
|
+
// Make assets with ASTs generate unless they are CSS modules. This parallelizes generation
|
|
305
|
+
// and distributes work more evenly across workers than if one worker needed to
|
|
306
|
+
// generate all assets in a large bundle during packaging.
|
|
307
|
+
await Promise.all(resultingAssets
|
|
308
|
+
.filter((asset) => asset.ast != null &&
|
|
309
|
+
!(this.options.mode === 'production' &&
|
|
310
|
+
asset.value.type === 'css' &&
|
|
311
|
+
asset.value.symbols))
|
|
312
|
+
.map(async (asset) => {
|
|
313
|
+
if (asset.isASTDirty && asset.generate) {
|
|
314
|
+
let output = await asset.generate();
|
|
315
|
+
asset.content = output.content;
|
|
316
|
+
asset.mapBuffer = output.map?.toBuffer();
|
|
317
|
+
}
|
|
318
|
+
asset.clearAST();
|
|
319
|
+
}));
|
|
320
|
+
return finalAssets.concat(resultingAssets);
|
|
321
|
+
}
|
|
322
|
+
async loadPipeline(filePath, isSource, pipeline) {
|
|
323
|
+
let transformers = await this.atlaspackConfig.getTransformers(filePath, pipeline, this.request.isURL);
|
|
324
|
+
for (let transformer of transformers) {
|
|
325
|
+
let config = await this.loadTransformerConfig(transformer, isSource);
|
|
326
|
+
if (config) {
|
|
327
|
+
this.configs.set(transformer.name, config);
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
return {
|
|
331
|
+
id: transformers.map((t) => t.name).join(':'),
|
|
332
|
+
transformers: transformers.map((transformer) => ({
|
|
333
|
+
name: transformer.name,
|
|
334
|
+
resolveFrom: transformer.resolveFrom,
|
|
335
|
+
config: this.configs.get(transformer.name)?.result,
|
|
336
|
+
configKeyPath: transformer.keyPath,
|
|
337
|
+
plugin: transformer.plugin,
|
|
338
|
+
})),
|
|
339
|
+
options: this.options,
|
|
340
|
+
pluginOptions: this.pluginOptions,
|
|
341
|
+
workerApi: this.workerApi,
|
|
342
|
+
};
|
|
343
|
+
}
|
|
344
|
+
async loadNextPipeline({ filePath, isSource, newType, newPipeline, currentPipeline, }) {
|
|
345
|
+
let filePathRelative = (0, projectPath_1.fromProjectPathRelative)(filePath);
|
|
346
|
+
let nextFilePath = (0, projectPath_1.toProjectPathUnsafe)(filePathRelative.slice(0, -path_1.default.extname(filePathRelative).length) +
|
|
347
|
+
'.' +
|
|
348
|
+
newType);
|
|
349
|
+
let nextPipeline = await this.loadPipeline(nextFilePath, isSource, newPipeline);
|
|
350
|
+
if (nextPipeline.id === currentPipeline.id) {
|
|
351
|
+
return null;
|
|
352
|
+
}
|
|
353
|
+
return nextPipeline;
|
|
354
|
+
}
|
|
355
|
+
async loadTransformerConfig(transformer, isSource) {
|
|
356
|
+
let loadConfig = transformer.plugin.loadConfig;
|
|
357
|
+
if (!loadConfig) {
|
|
358
|
+
return;
|
|
359
|
+
}
|
|
360
|
+
let config = (0, InternalConfig_1.createConfig)({
|
|
361
|
+
plugin: transformer.name,
|
|
362
|
+
isSource,
|
|
363
|
+
// @ts-expect-error TS2322
|
|
364
|
+
searchPath: this.request.filePath,
|
|
365
|
+
env: this.request.env,
|
|
366
|
+
});
|
|
367
|
+
await (0, ConfigRequest_1.loadPluginConfig)(transformer, config, this.options);
|
|
368
|
+
for (let devDep of config.devDeps) {
|
|
369
|
+
await this.addDevDependency(devDep);
|
|
370
|
+
}
|
|
371
|
+
return config;
|
|
372
|
+
}
|
|
373
|
+
async runTransformer(pipeline, asset, transformer, transformerName, preloadedConfig, configKeyPath, atlaspackConfig) {
|
|
374
|
+
const logger = new logger_1.PluginLogger({ origin: transformerName });
|
|
375
|
+
const tracer = new profiler_1.PluginTracer({
|
|
376
|
+
origin: transformerName,
|
|
377
|
+
category: 'transform',
|
|
378
|
+
});
|
|
379
|
+
const resolve = async (from, to, options) => {
|
|
380
|
+
let result = await this.resolverRunner.resolve((0, Dependency_1.createDependency)(this.options.projectRoot, {
|
|
381
|
+
env: asset.value.env,
|
|
382
|
+
specifier: to,
|
|
383
|
+
specifierType: options?.specifierType || 'esm',
|
|
384
|
+
packageConditions: options?.packageConditions,
|
|
385
|
+
sourcePath: from,
|
|
386
|
+
}));
|
|
387
|
+
if (result.invalidateOnFileCreate) {
|
|
388
|
+
this.invalidations.invalidateOnFileCreate.push(...result.invalidateOnFileCreate.map((i) => (0, utils_3.invalidateOnFileCreateToInternal)(this.options.projectRoot, i)));
|
|
389
|
+
}
|
|
390
|
+
if (result.invalidateOnFileChange) {
|
|
391
|
+
for (let filePath of result.invalidateOnFileChange) {
|
|
392
|
+
this.invalidations.invalidateOnFileChange.add((0, projectPath_1.toProjectPath)(this.options.projectRoot, filePath));
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
if (result.diagnostics && result.diagnostics.length > 0) {
|
|
396
|
+
throw new diagnostic_1.default({ diagnostic: result.diagnostics });
|
|
397
|
+
}
|
|
398
|
+
// @ts-expect-error TS2322
|
|
399
|
+
return (0, projectPath_1.fromProjectPath)(this.options.projectRoot, (0, nullthrows_1.default)(result.assetGroup).filePath);
|
|
400
|
+
};
|
|
401
|
+
// If an ast exists on the asset, but we cannot reuse it,
|
|
402
|
+
// use the previous transform to generate code that we can re-parse.
|
|
403
|
+
if (asset.ast &&
|
|
404
|
+
asset.isASTDirty &&
|
|
405
|
+
(!transformer.canReuseAST ||
|
|
406
|
+
!transformer.canReuseAST({
|
|
407
|
+
ast: asset.ast,
|
|
408
|
+
options: pipeline.pluginOptions,
|
|
409
|
+
logger,
|
|
410
|
+
tracer,
|
|
411
|
+
})) &&
|
|
412
|
+
asset.generate) {
|
|
413
|
+
let output = await asset.generate();
|
|
414
|
+
asset.content = output.content;
|
|
415
|
+
asset.mapBuffer = output.map?.toBuffer();
|
|
416
|
+
}
|
|
417
|
+
// Load config for the transformer.
|
|
418
|
+
let config = preloadedConfig;
|
|
419
|
+
// Parse if there is no AST available from a previous transform.
|
|
420
|
+
let parse = transformer.parse?.bind(transformer);
|
|
421
|
+
if (!asset.ast && parse) {
|
|
422
|
+
let ast = await parse({
|
|
423
|
+
asset: new Asset_1.Asset(asset),
|
|
424
|
+
config,
|
|
425
|
+
options: pipeline.pluginOptions,
|
|
426
|
+
resolve,
|
|
427
|
+
logger,
|
|
428
|
+
tracer,
|
|
429
|
+
});
|
|
430
|
+
if (ast) {
|
|
431
|
+
asset.setAST(ast);
|
|
432
|
+
asset.isASTDirty = false;
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
// Transform.
|
|
436
|
+
// @ts-expect-error TS2322
|
|
437
|
+
let transfomerResult = await transformer.transform({
|
|
438
|
+
asset: new Asset_1.MutableAsset(asset),
|
|
439
|
+
config,
|
|
440
|
+
options: pipeline.pluginOptions,
|
|
441
|
+
resolve,
|
|
442
|
+
logger,
|
|
443
|
+
tracer,
|
|
444
|
+
});
|
|
445
|
+
let results = await normalizeAssets(this.options, transfomerResult);
|
|
446
|
+
// Create generate and postProcess function that can be called later
|
|
447
|
+
asset.generate = () => {
|
|
448
|
+
let publicAsset = new Asset_1.Asset(asset);
|
|
449
|
+
if (transformer.generate && asset.ast) {
|
|
450
|
+
let generated = transformer.generate({
|
|
451
|
+
asset: publicAsset,
|
|
452
|
+
ast: asset.ast,
|
|
453
|
+
options: pipeline.pluginOptions,
|
|
454
|
+
logger,
|
|
455
|
+
tracer,
|
|
456
|
+
});
|
|
457
|
+
asset.clearAST();
|
|
458
|
+
return Promise.resolve(generated);
|
|
459
|
+
}
|
|
460
|
+
throw new Error('Asset has an AST but no generate method is available on the transform');
|
|
461
|
+
};
|
|
462
|
+
let postProcess = transformer.postProcess;
|
|
463
|
+
if (postProcess) {
|
|
464
|
+
pipeline.postProcess = async (assets) => {
|
|
465
|
+
let results = await postProcess.call(transformer, {
|
|
466
|
+
assets: assets.map((asset) => new Asset_1.MutableAsset(asset)),
|
|
467
|
+
config,
|
|
468
|
+
options: pipeline.pluginOptions,
|
|
469
|
+
resolve,
|
|
470
|
+
logger,
|
|
471
|
+
tracer,
|
|
472
|
+
});
|
|
473
|
+
return Promise.all(results.map((result) => asset.createChildAsset(result, transformerName, atlaspackConfig.filePath)));
|
|
474
|
+
};
|
|
475
|
+
}
|
|
476
|
+
return results;
|
|
477
|
+
}
|
|
478
|
+
}
|
|
479
|
+
exports.default = Transformation;
|
|
480
|
+
function normalizeAssets(options, results) {
|
|
481
|
+
return results.map((result) => {
|
|
482
|
+
if (result instanceof Asset_1.MutableAsset) {
|
|
483
|
+
return (0, Asset_1.mutableAssetToUncommittedAsset)(result);
|
|
484
|
+
}
|
|
485
|
+
return result;
|
|
486
|
+
});
|
|
487
|
+
}
|