@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.
- 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/package.json +22 -22
- package/src/AssetGraph.ts +1 -0
- package/tsconfig.json +55 -2
- package/tsconfig.tsbuildinfo +1 -0
|
@@ -0,0 +1,131 @@
|
|
|
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.assetGraphToDot = assetGraphToDot;
|
|
7
|
+
exports.getDebugAssetGraphDotPath = getDebugAssetGraphDotPath;
|
|
8
|
+
exports.getDebugAssetGraphDotOptions = getDebugAssetGraphDotOptions;
|
|
9
|
+
const path_1 = __importDefault(require("path"));
|
|
10
|
+
/** @description Renders AssetGraph into GraphViz Dot format */
|
|
11
|
+
function assetGraphToDot(assetGraph, { sort = false, style = true } = {}) {
|
|
12
|
+
const edges = [];
|
|
13
|
+
const nodeStyles = {};
|
|
14
|
+
assetGraph.traverse((nodeId) => {
|
|
15
|
+
let node = assetGraph.getNode(nodeId) ?? null;
|
|
16
|
+
if (!node)
|
|
17
|
+
return;
|
|
18
|
+
const fromIds = assetGraph.getNodeIdsConnectedTo(nodeId);
|
|
19
|
+
for (const fromId of fromIds) {
|
|
20
|
+
let fromNode = assetGraph.getNode(fromId) ?? null;
|
|
21
|
+
if (!fromNode)
|
|
22
|
+
throw new Error('No Node');
|
|
23
|
+
const edgeStyle = getEdgeStyle(node);
|
|
24
|
+
const nodeStyle = getNodeStyle(node);
|
|
25
|
+
let entry = `"${getNodeName(fromNode)}" -> "${getNodeName(node)}"`;
|
|
26
|
+
if (edgeStyle) {
|
|
27
|
+
entry += ` [${edgeStyle}]`;
|
|
28
|
+
}
|
|
29
|
+
if (nodeStyle) {
|
|
30
|
+
nodeStyles[getNodeName(node)] = nodeStyle;
|
|
31
|
+
}
|
|
32
|
+
edges.push(entry);
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
const nodeStylesList = Object.entries(nodeStyles);
|
|
36
|
+
if (sort) {
|
|
37
|
+
edges.sort();
|
|
38
|
+
nodeStylesList.sort();
|
|
39
|
+
}
|
|
40
|
+
let digraph = `digraph {\n\tnode [shape=rectangle]\n`;
|
|
41
|
+
if (style) {
|
|
42
|
+
digraph += nodeStylesList
|
|
43
|
+
.map(([node, style]) => `\t"${node}" [${style}]\n`)
|
|
44
|
+
.join('');
|
|
45
|
+
}
|
|
46
|
+
digraph += edges.map((v) => `\t${v}\n`).join('');
|
|
47
|
+
digraph += `}\n`;
|
|
48
|
+
return digraph;
|
|
49
|
+
}
|
|
50
|
+
function getDebugAssetGraphDotPath() {
|
|
51
|
+
let debugAssetGraphDot = process.env.DEBUG_ASSET_GRAPH_DOT;
|
|
52
|
+
if (debugAssetGraphDot === undefined || debugAssetGraphDot === '') {
|
|
53
|
+
return null;
|
|
54
|
+
}
|
|
55
|
+
if (!path_1.default.isAbsolute(debugAssetGraphDot)) {
|
|
56
|
+
debugAssetGraphDot = path_1.default.join(process.cwd(), debugAssetGraphDot);
|
|
57
|
+
}
|
|
58
|
+
return debugAssetGraphDot;
|
|
59
|
+
}
|
|
60
|
+
function getDebugAssetGraphDotOptions() {
|
|
61
|
+
const options = {};
|
|
62
|
+
let style = process.env.DEBUG_ASSET_GRAPH_DOT_STYLE;
|
|
63
|
+
if (style !== undefined) {
|
|
64
|
+
options.style = style === 'true';
|
|
65
|
+
}
|
|
66
|
+
let sort = process.env.DEBUG_ASSET_GRAPH_DOT_SORT;
|
|
67
|
+
if (sort !== undefined) {
|
|
68
|
+
options.sort = sort === 'true';
|
|
69
|
+
}
|
|
70
|
+
return options;
|
|
71
|
+
}
|
|
72
|
+
function fromCwd(input) {
|
|
73
|
+
return path_1.default.relative(process.cwd(), input);
|
|
74
|
+
}
|
|
75
|
+
function getNodeName(node) {
|
|
76
|
+
if (node.type === 'asset_group') {
|
|
77
|
+
// @ts-expect-error TS2345
|
|
78
|
+
return [`asset_group`, node.id, fromCwd(node.value.filePath)].join('\\n');
|
|
79
|
+
}
|
|
80
|
+
else if (node.type === 'asset') {
|
|
81
|
+
return [`asset`, node.id, fromCwd(node.value.filePath)].join('\\n');
|
|
82
|
+
}
|
|
83
|
+
else if (node.type === 'dependency') {
|
|
84
|
+
return [`dependency`, node.id, node.value.specifier].join('\\n');
|
|
85
|
+
}
|
|
86
|
+
else if (node.type === 'entry_specifier') {
|
|
87
|
+
return [`entry_specifier`, node.value].join('\\n');
|
|
88
|
+
}
|
|
89
|
+
else if (node.type === 'entry_file') {
|
|
90
|
+
return [`entry_file`, fromCwd(node.value.filePath)].join('\\n');
|
|
91
|
+
}
|
|
92
|
+
return 'ROOT';
|
|
93
|
+
}
|
|
94
|
+
function getEdgeStyle(node) {
|
|
95
|
+
if (node.type === 'asset_group') {
|
|
96
|
+
return ``;
|
|
97
|
+
}
|
|
98
|
+
else if (node.type === 'asset') {
|
|
99
|
+
return ``;
|
|
100
|
+
}
|
|
101
|
+
else if (node.type === 'dependency') {
|
|
102
|
+
if (node.value.priority === 2) {
|
|
103
|
+
return `style="dashed"`;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
else if (node.type === 'entry_specifier') {
|
|
107
|
+
return ``;
|
|
108
|
+
}
|
|
109
|
+
else if (node.type === 'entry_file') {
|
|
110
|
+
return ``;
|
|
111
|
+
}
|
|
112
|
+
return '';
|
|
113
|
+
}
|
|
114
|
+
function getNodeStyle(node) {
|
|
115
|
+
if (node.type === 'asset_group') {
|
|
116
|
+
return `fillcolor="#E8F5E9", style="filled"`;
|
|
117
|
+
}
|
|
118
|
+
else if (node.type === 'asset') {
|
|
119
|
+
return `fillcolor="#DCEDC8", style="filled"`;
|
|
120
|
+
}
|
|
121
|
+
else if (node.type === 'dependency') {
|
|
122
|
+
return `fillcolor="#BBDEFB", style="filled"`;
|
|
123
|
+
}
|
|
124
|
+
else if (node.type === 'entry_specifier') {
|
|
125
|
+
return `fillcolor="#FFF9C4", style="filled"`;
|
|
126
|
+
}
|
|
127
|
+
else if (node.type === 'entry_file') {
|
|
128
|
+
return `fillcolor="#FFE0B2", style="filled"`;
|
|
129
|
+
}
|
|
130
|
+
return '';
|
|
131
|
+
}
|
|
@@ -0,0 +1,268 @@
|
|
|
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.default = resolveOptions;
|
|
7
|
+
const path_1 = __importDefault(require("path"));
|
|
8
|
+
const rust_1 = require("@atlaspack/rust");
|
|
9
|
+
const fs_1 = require("@atlaspack/fs");
|
|
10
|
+
const cache_1 = require("@atlaspack/cache");
|
|
11
|
+
const feature_flags_1 = require("@atlaspack/feature-flags");
|
|
12
|
+
const package_manager_1 = require("@atlaspack/package-manager");
|
|
13
|
+
const utils_1 = require("@atlaspack/utils");
|
|
14
|
+
const loadDotEnv_1 = __importDefault(require("./loadDotEnv"));
|
|
15
|
+
const projectPath_1 = require("./projectPath");
|
|
16
|
+
const AtlaspackConfigRequest_1 = require("./requests/AtlaspackConfigRequest");
|
|
17
|
+
const feature_flags_2 = require("@atlaspack/feature-flags");
|
|
18
|
+
const constants_1 = require("./constants");
|
|
19
|
+
// Default cache directory name
|
|
20
|
+
const DEFAULT_CACHE_DIRNAME = '.parcel-cache';
|
|
21
|
+
const LOCK_FILE_NAMES = ['yarn.lock', 'package-lock.json', 'pnpm-lock.yaml'];
|
|
22
|
+
// Generate a unique instanceId, will change on every run of parcel
|
|
23
|
+
function generateInstanceId(entries) {
|
|
24
|
+
return (0, rust_1.hashString)(`${entries.join(',')}-${Date.now()}-${Math.round(Math.random() * 100)}`);
|
|
25
|
+
}
|
|
26
|
+
// Compiles an array of globs to regex - used for lazy include/excludes
|
|
27
|
+
function compileGlobs(globs) {
|
|
28
|
+
return globs.map((glob) => (0, utils_1.globToRegex)(glob));
|
|
29
|
+
}
|
|
30
|
+
function getDefaultFS() {
|
|
31
|
+
if ((0, feature_flags_1.getFeatureFlagValue)('vcsMode') !== 'OLD') {
|
|
32
|
+
return new fs_1.NodeVCSAwareFS({
|
|
33
|
+
gitRepoPath: null,
|
|
34
|
+
excludePatterns: [],
|
|
35
|
+
logEventDiff: () => { },
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
return new fs_1.NodeFS();
|
|
39
|
+
}
|
|
40
|
+
async function findGitRepositoryRoot(inputFS, projectRoot) {
|
|
41
|
+
let candidate = projectRoot;
|
|
42
|
+
while (candidate !== path_1.default.parse(candidate).root) {
|
|
43
|
+
const gitRepoPath = path_1.default.join(candidate, '.git');
|
|
44
|
+
if (await inputFS.exists(gitRepoPath)) {
|
|
45
|
+
return candidate;
|
|
46
|
+
}
|
|
47
|
+
candidate = path_1.default.dirname(candidate);
|
|
48
|
+
}
|
|
49
|
+
return null;
|
|
50
|
+
}
|
|
51
|
+
async function resolveOptions(initialOptions) {
|
|
52
|
+
const inputFS = initialOptions.inputFS || getDefaultFS();
|
|
53
|
+
const outputFS = initialOptions.outputFS || getDefaultFS();
|
|
54
|
+
let inputCwd = inputFS.cwd();
|
|
55
|
+
let outputCwd = outputFS.cwd();
|
|
56
|
+
let entries;
|
|
57
|
+
if (initialOptions.entries == null || initialOptions.entries === '') {
|
|
58
|
+
entries = [];
|
|
59
|
+
}
|
|
60
|
+
else if (Array.isArray(initialOptions.entries)) {
|
|
61
|
+
entries = initialOptions.entries.map((entry) => path_1.default.resolve(inputCwd, entry));
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
entries = [path_1.default.resolve(inputCwd, initialOptions.entries)];
|
|
65
|
+
}
|
|
66
|
+
// When allowExplicitTargetEntries is enabled and no entries are provided,
|
|
67
|
+
// automatically derive entries from target sources
|
|
68
|
+
if ((0, feature_flags_1.getFeatureFlag)('allowExplicitTargetEntries') &&
|
|
69
|
+
initialOptions.targets &&
|
|
70
|
+
!Array.isArray(initialOptions.targets) &&
|
|
71
|
+
entries.length === 0) {
|
|
72
|
+
const targetSources = new Set();
|
|
73
|
+
for (const [, target] of Object.entries(initialOptions.targets)) {
|
|
74
|
+
if (target.source) {
|
|
75
|
+
const sources = Array.isArray(target.source)
|
|
76
|
+
? target.source
|
|
77
|
+
: [target.source];
|
|
78
|
+
for (const source of sources) {
|
|
79
|
+
targetSources.add(source);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
entries = Array.from(targetSources);
|
|
84
|
+
}
|
|
85
|
+
let shouldMakeEntryReferFolder = false;
|
|
86
|
+
if (entries.length === 1 && !(0, utils_1.isGlob)(entries[0])) {
|
|
87
|
+
let [entry] = entries;
|
|
88
|
+
try {
|
|
89
|
+
shouldMakeEntryReferFolder = (await inputFS.stat(entry)).isDirectory();
|
|
90
|
+
}
|
|
91
|
+
catch {
|
|
92
|
+
// ignore failing stat call
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
let projectRoot;
|
|
96
|
+
if (initialOptions.projectRoot) {
|
|
97
|
+
// Use explicitly provided projectRoot
|
|
98
|
+
if (!path_1.default.isAbsolute(initialOptions.projectRoot)) {
|
|
99
|
+
throw new Error('Specified project root must be an absolute path');
|
|
100
|
+
}
|
|
101
|
+
projectRoot = initialOptions.projectRoot;
|
|
102
|
+
}
|
|
103
|
+
else {
|
|
104
|
+
// getRootDir treats the input as files, so getRootDir(["/home/user/myproject"]) returns "/home/user".
|
|
105
|
+
// Instead we need to make the the entry refer to some file inside the specified folders if entries refers to the directory.
|
|
106
|
+
let entryRoot = (0, utils_1.getRootDir)(shouldMakeEntryReferFolder ? [path_1.default.join(entries[0], 'index')] : entries);
|
|
107
|
+
let projectRootFile = (await (0, utils_1.resolveConfig)(inputFS, path_1.default.join(entryRoot, 'index'), [...LOCK_FILE_NAMES, '.git', '.hg'], path_1.default.parse(entryRoot).root)) || path_1.default.join(inputCwd, 'index'); // ? Should this just be rootDir
|
|
108
|
+
projectRoot = path_1.default.dirname(projectRootFile);
|
|
109
|
+
}
|
|
110
|
+
const gitRoot = await findGitRepositoryRoot(inputFS, projectRoot);
|
|
111
|
+
if (inputFS instanceof fs_1.NodeVCSAwareFS) {
|
|
112
|
+
inputFS.setGitRepoPath(gitRoot);
|
|
113
|
+
}
|
|
114
|
+
if (outputFS instanceof fs_1.NodeVCSAwareFS) {
|
|
115
|
+
outputFS.setGitRepoPath(gitRoot);
|
|
116
|
+
}
|
|
117
|
+
let packageManager = initialOptions.packageManager ||
|
|
118
|
+
new package_manager_1.NodePackageManager(inputFS, projectRoot);
|
|
119
|
+
let cacheDir =
|
|
120
|
+
// If a cacheDir is provided, resolve it relative to cwd. Otherwise,
|
|
121
|
+
// use a default directory resolved relative to the project root.
|
|
122
|
+
initialOptions.cacheDir != null
|
|
123
|
+
? path_1.default.resolve(outputCwd, initialOptions.cacheDir)
|
|
124
|
+
: path_1.default.resolve(projectRoot, DEFAULT_CACHE_DIRNAME);
|
|
125
|
+
// Make the root watch directory configurable. This is useful in some cases
|
|
126
|
+
// where symlinked dependencies outside the project root need to trigger HMR
|
|
127
|
+
// updates. Default to the project root if not provided.
|
|
128
|
+
let watchDir = initialOptions.watchDir != null
|
|
129
|
+
? path_1.default.resolve(initialOptions.watchDir)
|
|
130
|
+
: projectRoot;
|
|
131
|
+
function createCache() {
|
|
132
|
+
if (initialOptions.cache) {
|
|
133
|
+
return initialOptions.cache;
|
|
134
|
+
}
|
|
135
|
+
const needsRustLmdbCache = (0, feature_flags_1.getFeatureFlag)('atlaspackV3');
|
|
136
|
+
if (!(0, feature_flags_1.getFeatureFlag)('cachePerformanceImprovements')) {
|
|
137
|
+
if (!needsRustLmdbCache && !(outputFS instanceof fs_1.NodeFS)) {
|
|
138
|
+
return new cache_1.FSCache(outputFS, cacheDir);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
return new cache_1.LMDBLiteCache(cacheDir);
|
|
142
|
+
}
|
|
143
|
+
let cache = createCache();
|
|
144
|
+
let mode = initialOptions.mode ?? 'development';
|
|
145
|
+
let shouldOptimize = initialOptions?.defaultTargetOptions?.shouldOptimize ??
|
|
146
|
+
mode === 'production';
|
|
147
|
+
let publicUrl = initialOptions?.defaultTargetOptions?.publicUrl ?? '/';
|
|
148
|
+
let distDir = initialOptions?.defaultTargetOptions?.distDir != null
|
|
149
|
+
? path_1.default.resolve(inputCwd, initialOptions?.defaultTargetOptions?.distDir)
|
|
150
|
+
: undefined;
|
|
151
|
+
let shouldBuildLazily = initialOptions.shouldBuildLazily ?? false;
|
|
152
|
+
let lazyIncludes = compileGlobs(initialOptions.lazyIncludes ?? []);
|
|
153
|
+
if (lazyIncludes.length > 0 && !shouldBuildLazily) {
|
|
154
|
+
throw new Error('Lazy includes can only be provided when lazy building is enabled');
|
|
155
|
+
}
|
|
156
|
+
let lazyExcludes = compileGlobs(initialOptions.lazyExcludes ?? []);
|
|
157
|
+
if (lazyExcludes.length > 0 && !shouldBuildLazily) {
|
|
158
|
+
throw new Error('Lazy excludes can only be provided when lazy building is enabled');
|
|
159
|
+
}
|
|
160
|
+
let shouldContentHash = initialOptions.shouldContentHash ?? initialOptions.mode === 'production';
|
|
161
|
+
if (shouldBuildLazily && shouldContentHash) {
|
|
162
|
+
throw new Error('Lazy bundling does not work with content hashing');
|
|
163
|
+
}
|
|
164
|
+
let env = {
|
|
165
|
+
...(await (0, loadDotEnv_1.default)(initialOptions.env ?? {}, inputFS, path_1.default.join(projectRoot, 'index'), projectRoot)),
|
|
166
|
+
...process.env,
|
|
167
|
+
...initialOptions.env,
|
|
168
|
+
};
|
|
169
|
+
let port = determinePort(initialOptions.serveOptions, env.PORT);
|
|
170
|
+
return {
|
|
171
|
+
config: getRelativeConfigSpecifier(inputFS, projectRoot, initialOptions.config),
|
|
172
|
+
defaultConfig: getRelativeConfigSpecifier(inputFS, projectRoot, initialOptions.defaultConfig),
|
|
173
|
+
shouldPatchConsole: initialOptions.shouldPatchConsole ?? false,
|
|
174
|
+
env,
|
|
175
|
+
mode,
|
|
176
|
+
shouldAutoInstall: initialOptions.shouldAutoInstall ?? false,
|
|
177
|
+
hmrOptions: initialOptions.hmrOptions ?? null,
|
|
178
|
+
shouldBuildLazily,
|
|
179
|
+
lazyIncludes,
|
|
180
|
+
lazyExcludes,
|
|
181
|
+
unstableFileInvalidations: initialOptions.unstableFileInvalidations,
|
|
182
|
+
shouldBundleIncrementally: initialOptions.shouldBundleIncrementally ?? true,
|
|
183
|
+
shouldContentHash,
|
|
184
|
+
serveOptions: initialOptions.serveOptions
|
|
185
|
+
? {
|
|
186
|
+
...initialOptions.serveOptions,
|
|
187
|
+
distDir: distDir ?? path_1.default.join(outputCwd, 'dist'),
|
|
188
|
+
port,
|
|
189
|
+
}
|
|
190
|
+
: false,
|
|
191
|
+
shouldDisableCache: initialOptions.shouldDisableCache ?? false,
|
|
192
|
+
shouldProfile: initialOptions.shouldProfile ?? false,
|
|
193
|
+
shouldTrace: initialOptions.shouldTrace ?? false,
|
|
194
|
+
cacheDir,
|
|
195
|
+
watchDir,
|
|
196
|
+
watchBackend: initialOptions.watchBackend ?? 'watchman',
|
|
197
|
+
watchIgnore: initialOptions.watchIgnore,
|
|
198
|
+
entries: entries.map((e) => (0, projectPath_1.toProjectPath)(projectRoot, e)),
|
|
199
|
+
targets: initialOptions.targets,
|
|
200
|
+
logLevel: initialOptions.logLevel ?? 'info',
|
|
201
|
+
projectRoot,
|
|
202
|
+
inputFS,
|
|
203
|
+
outputFS,
|
|
204
|
+
cache,
|
|
205
|
+
packageManager,
|
|
206
|
+
additionalReporters: initialOptions.additionalReporters?.map(({ packageName, resolveFrom }) => ({
|
|
207
|
+
packageName,
|
|
208
|
+
resolveFrom: (0, projectPath_1.toProjectPath)(projectRoot, resolveFrom),
|
|
209
|
+
})) ?? [],
|
|
210
|
+
instanceId: generateInstanceId(entries),
|
|
211
|
+
detailedReport: initialOptions.detailedReport,
|
|
212
|
+
defaultTargetOptions: {
|
|
213
|
+
shouldOptimize,
|
|
214
|
+
shouldScopeHoist: initialOptions?.defaultTargetOptions?.shouldScopeHoist,
|
|
215
|
+
sourceMaps: initialOptions?.defaultTargetOptions?.sourceMaps ?? true,
|
|
216
|
+
publicUrl,
|
|
217
|
+
...(distDir != null
|
|
218
|
+
? { distDir: (0, projectPath_1.toProjectPath)(projectRoot, distDir) }
|
|
219
|
+
: {
|
|
220
|
+
/*::...null*/
|
|
221
|
+
}),
|
|
222
|
+
engines: initialOptions?.defaultTargetOptions?.engines,
|
|
223
|
+
outputFormat: initialOptions?.defaultTargetOptions?.outputFormat,
|
|
224
|
+
isLibrary: initialOptions?.defaultTargetOptions?.isLibrary,
|
|
225
|
+
},
|
|
226
|
+
// unused, feature-flags are set above this to allow this function to use
|
|
227
|
+
// feature-flags
|
|
228
|
+
featureFlags: { ...feature_flags_2.DEFAULT_FEATURE_FLAGS, ...initialOptions?.featureFlags },
|
|
229
|
+
parcelVersion: constants_1.ATLASPACK_VERSION,
|
|
230
|
+
};
|
|
231
|
+
}
|
|
232
|
+
function getRelativeConfigSpecifier(fs, projectRoot, specifier) {
|
|
233
|
+
if (specifier == null) {
|
|
234
|
+
return undefined;
|
|
235
|
+
}
|
|
236
|
+
else if (path_1.default.isAbsolute(specifier)) {
|
|
237
|
+
let resolveFrom = (0, AtlaspackConfigRequest_1.getResolveFrom)(fs, projectRoot);
|
|
238
|
+
let relative = (0, utils_1.relativePath)(path_1.default.dirname(resolveFrom), specifier);
|
|
239
|
+
// If the config is outside the project root, use an absolute path so that if the project root
|
|
240
|
+
// moves the path still works. Otherwise, use a relative path so that the cache is portable.
|
|
241
|
+
return relative.startsWith('..') ? specifier : relative;
|
|
242
|
+
}
|
|
243
|
+
else {
|
|
244
|
+
return specifier;
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
function determinePort(initialServerOptions, portInEnv, defaultPort = 1234) {
|
|
248
|
+
function parsePort(port) {
|
|
249
|
+
let parsedPort = Number(port);
|
|
250
|
+
// return undefined if port number defined in .env is not valid integer
|
|
251
|
+
if (!Number.isInteger(parsedPort)) {
|
|
252
|
+
return undefined;
|
|
253
|
+
}
|
|
254
|
+
return parsedPort;
|
|
255
|
+
}
|
|
256
|
+
if (!initialServerOptions) {
|
|
257
|
+
return typeof portInEnv !== 'undefined'
|
|
258
|
+
? (parsePort(portInEnv) ?? defaultPort)
|
|
259
|
+
: defaultPort;
|
|
260
|
+
}
|
|
261
|
+
// if initialServerOptions.port is equal to defaultPort, then this means that port number is provided via PORT=~~~~ on cli. In this case, we should ignore port number defined in .env.
|
|
262
|
+
if (initialServerOptions.port !== defaultPort) {
|
|
263
|
+
return initialServerOptions.port;
|
|
264
|
+
}
|
|
265
|
+
return typeof portInEnv !== 'undefined'
|
|
266
|
+
? (parsePort(portInEnv) ?? defaultPort)
|
|
267
|
+
: defaultPort;
|
|
268
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.loadRustWorkerThreadDylibHack = loadRustWorkerThreadDylibHack;
|
|
4
|
+
/**
|
|
5
|
+
* This is a workaround for https://github.com/rust-lang/rust/issues/91979
|
|
6
|
+
* when running atlaspack with parcel bindings, it is possible that the parcel
|
|
7
|
+
* dylib will be loaded from a node worker thread, which causes a crash on exit.
|
|
8
|
+
*
|
|
9
|
+
* This is a workaround to ensure that the parcel dylib is loaded in the main
|
|
10
|
+
* thread, which fixes the crash.
|
|
11
|
+
*/
|
|
12
|
+
function loadRustWorkerThreadDylibHack() {
|
|
13
|
+
try {
|
|
14
|
+
require('@parcel/rust'); // eslint-disable-line
|
|
15
|
+
}
|
|
16
|
+
catch (err) {
|
|
17
|
+
/* ignore */
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.deserializeRaw = exports.serializeRaw = void 0;
|
|
37
|
+
const buffer_1 = require("buffer");
|
|
38
|
+
const msgpackr = __importStar(require("msgpackr"));
|
|
39
|
+
let encoder = new msgpackr.Encoder({ structuredClone: true });
|
|
40
|
+
let serializeRaw = (v) => buffer_1.Buffer.from(encoder.encode(v));
|
|
41
|
+
exports.serializeRaw = serializeRaw;
|
|
42
|
+
let deserializeRaw = (v) => encoder.decode(v);
|
|
43
|
+
exports.deserializeRaw = deserializeRaw;
|
|
@@ -0,0 +1,39 @@
|
|
|
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.default = summarizeRequest;
|
|
7
|
+
const path_1 = __importDefault(require("path"));
|
|
8
|
+
const NODE_MODULES = `${path_1.default.sep}node_modules${path_1.default.sep}`;
|
|
9
|
+
const BUFFER_LIMIT = 5000000; // 5mb
|
|
10
|
+
async function summarizeRequest(fs, req) {
|
|
11
|
+
let { content, size } = await summarizeDiskRequest(fs, req);
|
|
12
|
+
let isSource = isFilePathSource(fs, req.filePath);
|
|
13
|
+
return { content, size, isSource };
|
|
14
|
+
}
|
|
15
|
+
function isFilePathSource(fs, filePath) {
|
|
16
|
+
return !filePath.includes(NODE_MODULES);
|
|
17
|
+
}
|
|
18
|
+
async function summarizeDiskRequest(fs, req) {
|
|
19
|
+
let code = req.code;
|
|
20
|
+
let content;
|
|
21
|
+
let size;
|
|
22
|
+
if (code == null) {
|
|
23
|
+
// Get the filesize. If greater than BUFFER_LIMIT, use a stream to
|
|
24
|
+
// compute the hash. In the common case, it's faster to just read the entire
|
|
25
|
+
// file first and do the hash all at once without the overhead of streams.
|
|
26
|
+
size = (await fs.stat(req.filePath)).size;
|
|
27
|
+
if (size > BUFFER_LIMIT) {
|
|
28
|
+
content = fs.createReadStream(req.filePath);
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
content = await fs.readFile(req.filePath);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
content = code;
|
|
36
|
+
size = Buffer.byteLength(code);
|
|
37
|
+
}
|
|
38
|
+
return { content, size };
|
|
39
|
+
}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BundleBehaviorNames = exports.BundleBehavior = exports.ExportsCondition = exports.Priority = exports.SpecifierType = void 0;
|
|
4
|
+
exports.SpecifierType = {
|
|
5
|
+
esm: 0,
|
|
6
|
+
commonjs: 1,
|
|
7
|
+
url: 2,
|
|
8
|
+
custom: 3,
|
|
9
|
+
};
|
|
10
|
+
exports.Priority = {
|
|
11
|
+
sync: 0,
|
|
12
|
+
parallel: 1,
|
|
13
|
+
lazy: 2,
|
|
14
|
+
conditional: 3,
|
|
15
|
+
};
|
|
16
|
+
// Must match package_json.rs in node-resolver-rs.
|
|
17
|
+
exports.ExportsCondition = {
|
|
18
|
+
import: 1 << 0,
|
|
19
|
+
require: 1 << 1,
|
|
20
|
+
module: 1 << 2,
|
|
21
|
+
style: 1 << 12,
|
|
22
|
+
sass: 1 << 13,
|
|
23
|
+
less: 1 << 14,
|
|
24
|
+
};
|
|
25
|
+
exports.BundleBehavior = {
|
|
26
|
+
inline: 0,
|
|
27
|
+
isolated: 1,
|
|
28
|
+
inlineIsolated: 2,
|
|
29
|
+
};
|
|
30
|
+
// @ts-expect-error TS2322
|
|
31
|
+
exports.BundleBehaviorNames = Object.keys(exports.BundleBehavior);
|