@atlaspack/utils 2.14.5-canary.36 → 2.14.5-canary.360
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 +462 -0
- package/benchmark.js +23 -0
- package/dist/DefaultMap.js +41 -0
- package/dist/Deferred.js +16 -0
- package/dist/PromiseQueue.js +107 -0
- package/dist/TapStream.js +23 -0
- package/dist/alternatives.js +97 -0
- package/dist/ansi-html.js +12 -0
- package/dist/blob.js +29 -0
- package/dist/bundle-url.js +32 -0
- package/dist/collection.js +106 -0
- package/dist/config.js +138 -0
- package/dist/countLines.js +12 -0
- package/dist/debounce.js +15 -0
- package/dist/debug-tools.js +39 -0
- package/dist/dependency-location.js +22 -0
- package/dist/escape-html.js +19 -0
- package/dist/generateBuildMetrics.js +111 -0
- package/dist/generateCertificate.js +124 -0
- package/dist/getCertificate.js +13 -0
- package/dist/getExisting.js +20 -0
- package/dist/getModuleParts.js +27 -0
- package/dist/getRootDir.js +46 -0
- package/dist/getTimeId.js +13 -0
- package/dist/glob.js +129 -0
- package/dist/hash.js +45 -0
- package/dist/http-server.js +55 -0
- package/dist/index.js +148 -0
- package/dist/is-url.js +15 -0
- package/dist/isDirectoryInside.js +11 -0
- package/dist/objectHash.js +20 -0
- package/dist/openInBrowser.js +61 -0
- package/dist/parseCSSImport.js +14 -0
- package/dist/path.js +36 -0
- package/dist/prettifyTime.js +6 -0
- package/dist/prettyDiagnostic.js +108 -0
- package/dist/progress-message.js +31 -0
- package/dist/relativeBundlePath.js +13 -0
- package/dist/relativeUrl.js +11 -0
- package/dist/replaceBundleReferences.js +131 -0
- package/dist/schema.js +404 -0
- package/dist/shared-buffer.js +24 -0
- package/dist/sourcemap.js +121 -0
- package/dist/stream.js +69 -0
- package/dist/throttle.js +12 -0
- package/dist/urlJoin.js +22 -0
- package/lib/DefaultMap.js +42 -0
- package/lib/Deferred.js +30 -0
- package/lib/PromiseQueue.js +112 -0
- package/lib/TapStream.js +34 -0
- package/lib/alternatives.js +116 -0
- package/lib/ansi-html.js +20 -0
- package/lib/blob.js +40 -0
- package/lib/bundle-url.js +34 -0
- package/lib/collection.js +111 -0
- package/lib/config.js +174 -0
- package/lib/countLines.js +15 -0
- package/lib/debounce.js +18 -0
- package/lib/debug-tools.js +40 -0
- package/lib/dependency-location.js +21 -0
- package/lib/escape-html.js +22 -0
- package/lib/generateBuildMetrics.js +121 -0
- package/lib/generateCertificate.js +129 -0
- package/lib/getCertificate.js +18 -0
- package/lib/getExisting.js +25 -0
- package/lib/getModuleParts.js +30 -0
- package/lib/getRootDir.js +52 -0
- package/lib/getTimeId.js +10 -0
- package/lib/glob.js +110 -0
- package/lib/hash.js +50 -0
- package/lib/http-server.js +85 -0
- package/lib/index.js +643 -37310
- package/lib/is-url.js +24 -0
- package/lib/isDirectoryInside.js +18 -0
- package/lib/objectHash.js +26 -0
- package/lib/openInBrowser.js +74 -0
- package/lib/parseCSSImport.js +15 -0
- package/lib/path.js +39 -0
- package/lib/prettifyTime.js +9 -0
- package/lib/prettyDiagnostic.js +154 -0
- package/lib/progress-message.js +39 -0
- package/lib/relativeBundlePath.js +22 -0
- package/lib/relativeUrl.js +24 -0
- package/lib/replaceBundleReferences.js +182 -0
- package/lib/schema.js +353 -0
- package/lib/shared-buffer.js +31 -0
- package/lib/sourcemap.js +138 -0
- package/lib/stream.js +76 -0
- package/lib/throttle.js +15 -0
- package/lib/types/DefaultMap.d.ts +13 -0
- package/lib/types/Deferred.d.ts +8 -0
- package/lib/types/PromiseQueue.d.ts +25 -0
- package/lib/types/TapStream.d.ts +6 -0
- package/lib/types/alternatives.d.ts +3 -0
- package/lib/types/ansi-html.d.ts +1 -0
- package/lib/types/blob.d.ts +4 -0
- package/lib/types/bundle-url.d.ts +4 -0
- package/lib/types/collection.d.ts +33 -0
- package/lib/types/config.d.ts +17 -0
- package/lib/types/countLines.d.ts +1 -0
- package/lib/types/debounce.d.ts +1 -0
- package/lib/types/debug-tools.d.ts +8 -0
- package/lib/types/dependency-location.d.ts +14 -0
- package/lib/types/escape-html.d.ts +1 -0
- package/lib/types/generateBuildMetrics.d.ts +18 -0
- package/lib/types/generateCertificate.d.ts +5 -0
- package/lib/types/getCertificate.d.ts +5 -0
- package/lib/types/getExisting.d.ts +8 -0
- package/lib/types/getModuleParts.d.ts +4 -0
- package/lib/types/getRootDir.d.ts +2 -0
- package/lib/types/getTimeId.d.ts +1 -0
- package/lib/types/glob.d.ts +9 -0
- package/lib/types/hash.d.ts +7 -0
- package/lib/types/http-server.d.ts +19 -0
- package/lib/types/index.d.ts +49 -0
- package/lib/types/is-url.d.ts +1 -0
- package/lib/types/isDirectoryInside.d.ts +2 -0
- package/lib/types/objectHash.d.ts +3 -0
- package/lib/types/openInBrowser.d.ts +1 -0
- package/lib/types/parseCSSImport.d.ts +1 -0
- package/lib/types/path.d.ts +8 -0
- package/lib/types/prettifyTime.d.ts +1 -0
- package/lib/types/prettyDiagnostic.d.ts +18 -0
- package/lib/types/progress-message.d.ts +3 -0
- package/lib/types/relativeBundlePath.d.ts +4 -0
- package/lib/types/relativeUrl.d.ts +1 -0
- package/lib/types/replaceBundleReferences.d.ts +39 -0
- package/lib/types/schema.d.ts +107 -0
- package/lib/types/shared-buffer.d.ts +2 -0
- package/lib/types/sourcemap.d.ts +15 -0
- package/lib/types/stream.d.ts +8 -0
- package/lib/types/throttle.d.ts +1 -0
- package/lib/types/urlJoin.d.ts +5 -0
- package/lib/urlJoin.js +35 -0
- package/package.json +27 -18
- package/src/{DefaultMap.js → DefaultMap.ts} +8 -12
- package/src/Deferred.ts +26 -0
- package/src/{PromiseQueue.js → PromiseQueue.ts} +40 -35
- package/src/{TapStream.js → TapStream.ts} +8 -7
- package/src/{alternatives.js → alternatives.ts} +15 -16
- package/src/{ansi-html.js → ansi-html.ts} +1 -1
- package/src/{blob.js → blob.ts} +3 -5
- package/src/{bundle-url.js → bundle-url.ts} +3 -5
- package/src/{collection.js → collection.ts} +23 -20
- package/src/{config.js → config.ts} +20 -21
- package/src/{countLines.js → countLines.ts} +0 -2
- package/src/{debounce.js → debounce.ts} +3 -5
- package/src/debug-tools.ts +48 -0
- package/src/{dependency-location.js → dependency-location.ts} +15 -11
- package/src/{escape-html.js → escape-html.ts} +5 -3
- package/src/{generateBuildMetrics.js → generateBuildMetrics.ts} +19 -21
- package/src/{generateCertificate.js → generateCertificate.ts} +8 -6
- package/src/{getCertificate.js → getCertificate.ts} +6 -5
- package/src/{getExisting.js → getExisting.ts} +4 -3
- package/src/{getModuleParts.js → getModuleParts.ts} +3 -2
- package/src/{getRootDir.js → getRootDir.ts} +1 -3
- package/src/getTimeId.ts +12 -0
- package/src/{glob.js → glob.ts} +13 -14
- package/src/{hash.js → hash.ts} +23 -18
- package/src/{http-server.js → http-server.ts} +34 -40
- package/src/{index.js → index.ts} +14 -10
- package/src/{is-url.js → is-url.ts} +1 -2
- package/src/{isDirectoryInside.js → isDirectoryInside.ts} +1 -2
- package/src/{objectHash.js → objectHash.ts} +1 -4
- package/src/{openInBrowser.js → openInBrowser.ts} +2 -4
- package/src/{parseCSSImport.js → parseCSSImport.ts} +0 -2
- package/src/{path.js → path.ts} +2 -4
- package/src/{prettifyTime.js → prettifyTime.ts} +0 -2
- package/src/{prettyDiagnostic.js → prettyDiagnostic.ts} +47 -24
- package/src/progress-message.ts +43 -0
- package/src/{relativeBundlePath.js → relativeBundlePath.ts} +4 -4
- package/src/{relativeUrl.js → relativeUrl.ts} +0 -1
- package/src/{replaceBundleReferences.js → replaceBundleReferences.ts} +67 -51
- package/src/schema.ts +552 -0
- package/src/{shared-buffer.js → shared-buffer.ts} +5 -3
- package/src/{sourcemap.js → sourcemap.ts} +28 -10
- package/src/{stream.js → stream.ts} +30 -22
- package/src/throttle.ts +13 -0
- package/src/{urlJoin.js → urlJoin.ts} +1 -3
- package/test/{DefaultMap.test.js → DefaultMap.test.ts} +4 -6
- package/test/{PromiseQueue.test.js → PromiseQueue.test.ts} +5 -6
- package/test/{collection.test.js → collection.test.ts} +0 -2
- package/test/{config.test.js → config.test.ts} +0 -3
- package/test/{objectHash.test.js → objectHash.test.ts} +4 -5
- package/test/{prettifyTime.test.js → prettifyTime.test.ts} +0 -1
- package/test/{replaceBundleReferences.test.js → replaceBundleReferences.test.ts} +0 -32
- package/test/schema.test.ts +748 -0
- package/test/{sourcemap.test.js → sourcemap.test.ts} +0 -1
- package/test/{throttle.test.js → throttle.test.ts} +1 -3
- package/test/{urlJoin.test.js → urlJoin.test.ts} +0 -2
- package/tsconfig.json +36 -0
- package/tsconfig.tsbuildinfo +1 -0
- package/lib/index.js.map +0 -1
- package/src/Deferred.js +0 -23
- package/src/progress-message.js +0 -22
- package/src/schema.js +0 -504
- package/src/throttle.js +0 -15
|
@@ -1,41 +1,39 @@
|
|
|
1
|
-
// @flow strict-local
|
|
2
1
|
import type {Diagnostic} from '@atlaspack/diagnostic';
|
|
3
|
-
import type {PluginOptions} from '@atlaspack/types';
|
|
2
|
+
import type {PluginOptions} from '@atlaspack/types-internal';
|
|
4
3
|
|
|
5
4
|
import formatCodeFrame from '@atlaspack/codeframe';
|
|
5
|
+
import logger from '@atlaspack/logger';
|
|
6
6
|
import _mdAnsi from '@atlaspack/markdown-ansi';
|
|
7
7
|
import _chalk from 'chalk';
|
|
8
8
|
import path from 'path';
|
|
9
|
-
// $FlowFixMe
|
|
10
9
|
import _terminalLink from 'terminal-link';
|
|
11
10
|
|
|
12
11
|
/* eslint-disable import/no-extraneous-dependencies */
|
|
13
|
-
// $FlowFixMe
|
|
14
12
|
import snarkdown from 'snarkdown';
|
|
15
13
|
/* eslint-enable import/no-extraneous-dependencies */
|
|
16
14
|
|
|
17
|
-
export type FormattedCodeFrame = {
|
|
18
|
-
location: string
|
|
19
|
-
code: string
|
|
20
|
-
|
|
15
|
+
export type FormattedCodeFrame = {
|
|
16
|
+
location: string;
|
|
17
|
+
code: string;
|
|
18
|
+
};
|
|
21
19
|
|
|
22
|
-
export type AnsiDiagnosticResult = {
|
|
23
|
-
message: string
|
|
24
|
-
stack: string
|
|
20
|
+
export type AnsiDiagnosticResult = {
|
|
21
|
+
message: string;
|
|
22
|
+
stack: string;
|
|
25
23
|
/** A formatted string containing all code frames, including their file locations. */
|
|
26
|
-
codeframe: string
|
|
24
|
+
codeframe: string;
|
|
27
25
|
/** A list of code frames with highlighted code and file locations separately. */
|
|
28
|
-
frames: Array<FormattedCodeFrame
|
|
29
|
-
hints: Array<string
|
|
30
|
-
documentation: string
|
|
31
|
-
|
|
26
|
+
frames: Array<FormattedCodeFrame>;
|
|
27
|
+
hints: Array<string>;
|
|
28
|
+
documentation: string;
|
|
29
|
+
};
|
|
32
30
|
|
|
33
|
-
export
|
|
31
|
+
export function prettyDiagnosticSync(
|
|
34
32
|
diagnostic: Diagnostic,
|
|
35
33
|
options?: PluginOptions,
|
|
36
34
|
terminalWidth?: number,
|
|
37
35
|
format: 'ansi' | 'html' = 'ansi',
|
|
38
|
-
):
|
|
36
|
+
): AnsiDiagnosticResult {
|
|
39
37
|
let {
|
|
40
38
|
origin,
|
|
41
39
|
message,
|
|
@@ -51,18 +49,24 @@ export default async function prettyDiagnostic(
|
|
|
51
49
|
format === 'ansi'
|
|
52
50
|
? _terminalLink
|
|
53
51
|
: // eslint-disable-next-line no-unused-vars
|
|
54
|
-
(
|
|
52
|
+
(
|
|
53
|
+
text: string,
|
|
54
|
+
url: string,
|
|
55
|
+
_: {
|
|
56
|
+
fallback: (text: never, url: never) => string;
|
|
57
|
+
},
|
|
58
|
+
) => `<a href="${url}">${text}</a>`;
|
|
55
59
|
const chalk =
|
|
56
60
|
format === 'ansi'
|
|
57
61
|
? _chalk
|
|
58
62
|
: {
|
|
59
63
|
gray: {
|
|
60
|
-
underline: (v) =>
|
|
64
|
+
underline: (v: string) =>
|
|
61
65
|
`<span style="color: grey; text-decoration: underline;">${v}</span>`,
|
|
62
66
|
},
|
|
63
67
|
};
|
|
64
68
|
|
|
65
|
-
let result = {
|
|
69
|
+
let result: AnsiDiagnosticResult = {
|
|
66
70
|
message:
|
|
67
71
|
md(`**${origin ?? 'unknown'}**: `) +
|
|
68
72
|
(skipFormatting ? message : md(message)),
|
|
@@ -83,7 +87,16 @@ export default async function prettyDiagnostic(
|
|
|
83
87
|
let highlights = codeFrame.codeHighlights;
|
|
84
88
|
let code = codeFrame.code;
|
|
85
89
|
if (code == null && options && filePath != null) {
|
|
86
|
-
|
|
90
|
+
try {
|
|
91
|
+
code = options.inputFS.readFileSync(filePath, 'utf8');
|
|
92
|
+
} catch (e) {
|
|
93
|
+
// In strange cases this can fail and hide the underlying error.
|
|
94
|
+
logger.warn({
|
|
95
|
+
origin: '@atlaspack/utils',
|
|
96
|
+
message: `Failed to read file for generating codeframe: "${filePath}"`,
|
|
97
|
+
skipFormatting: true,
|
|
98
|
+
});
|
|
99
|
+
}
|
|
87
100
|
}
|
|
88
101
|
|
|
89
102
|
let formattedCodeFrame = '';
|
|
@@ -92,7 +105,6 @@ export default async function prettyDiagnostic(
|
|
|
92
105
|
useColor: true,
|
|
93
106
|
syntaxHighlighting: true,
|
|
94
107
|
language:
|
|
95
|
-
// $FlowFixMe sketchy null checks do not matter here...
|
|
96
108
|
codeFrame.language ||
|
|
97
109
|
(filePath != null ? path.extname(filePath).substr(1) : undefined),
|
|
98
110
|
terminalWidth,
|
|
@@ -132,9 +144,20 @@ export default async function prettyDiagnostic(
|
|
|
132
144
|
|
|
133
145
|
if (documentationURL != null) {
|
|
134
146
|
result.documentation = terminalLink('Learn more', documentationURL, {
|
|
135
|
-
fallback: (text, url) => `${text}: ${url}`,
|
|
147
|
+
fallback: (text: string, url: string) => `${text}: ${url}`,
|
|
136
148
|
});
|
|
137
149
|
}
|
|
138
150
|
|
|
139
151
|
return result;
|
|
140
152
|
}
|
|
153
|
+
|
|
154
|
+
export default function prettyDiagnostic(
|
|
155
|
+
diagnostic: Diagnostic,
|
|
156
|
+
options?: PluginOptions,
|
|
157
|
+
terminalWidth?: number,
|
|
158
|
+
format: 'ansi' | 'html' = 'ansi',
|
|
159
|
+
): Promise<AnsiDiagnosticResult> {
|
|
160
|
+
return Promise.resolve(
|
|
161
|
+
prettyDiagnosticSync(diagnostic, options, terminalWidth, format),
|
|
162
|
+
);
|
|
163
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type {BuildProgressEvent} from '@atlaspack/types-internal';
|
|
2
|
+
|
|
3
|
+
import path from 'path';
|
|
4
|
+
|
|
5
|
+
export function getProgressMessage(
|
|
6
|
+
event: BuildProgressEvent,
|
|
7
|
+
): string | null | undefined {
|
|
8
|
+
switch (event.phase) {
|
|
9
|
+
case 'transforming':
|
|
10
|
+
return `Building ${path.basename(event.filePath)}...`;
|
|
11
|
+
|
|
12
|
+
case 'bundling':
|
|
13
|
+
return 'Bundling...';
|
|
14
|
+
|
|
15
|
+
case 'packaging':
|
|
16
|
+
return `Packaging ${event.bundle.displayName}...`;
|
|
17
|
+
|
|
18
|
+
case 'optimizing':
|
|
19
|
+
return `Optimizing ${event.bundle.displayName}...`;
|
|
20
|
+
|
|
21
|
+
case 'packagingAndOptimizing': {
|
|
22
|
+
return getPackageProgressMessage(
|
|
23
|
+
event.completeBundles,
|
|
24
|
+
event.totalBundles,
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export function getPackageProgressMessage(
|
|
33
|
+
completeBundles: number,
|
|
34
|
+
totalBundles: number,
|
|
35
|
+
): string {
|
|
36
|
+
let percent = Math.floor((completeBundles / totalBundles) * 100);
|
|
37
|
+
let completeStr = completeBundles.toString();
|
|
38
|
+
let totalStr = totalBundles.toString();
|
|
39
|
+
|
|
40
|
+
let displayBundles = completeStr.padStart(totalStr.length, ' ');
|
|
41
|
+
|
|
42
|
+
return `Packaging bundles ${displayBundles}/${totalBundles} (${percent}%)`;
|
|
43
|
+
}
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import type {FilePath, NamedBundle} from '@atlaspack/types';
|
|
1
|
+
import type {FilePath, NamedBundle} from '@atlaspack/types-internal';
|
|
4
2
|
|
|
5
3
|
import path from 'path';
|
|
6
4
|
import {relativePath} from './path';
|
|
@@ -8,7 +6,9 @@ import {relativePath} from './path';
|
|
|
8
6
|
export function relativeBundlePath(
|
|
9
7
|
from: NamedBundle,
|
|
10
8
|
to: NamedBundle,
|
|
11
|
-
opts: {
|
|
9
|
+
opts: {
|
|
10
|
+
leadingDotSlash: boolean;
|
|
11
|
+
} = {leadingDotSlash: true},
|
|
12
12
|
): FilePath {
|
|
13
13
|
let fromPath = path.join(from.target.distDir, from.name);
|
|
14
14
|
let toPath = path.join(to.target.distDir, to.name);
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import type SourceMap from '@parcel/source-map';
|
|
1
|
+
import type SourceMap from '@atlaspack/source-map';
|
|
4
2
|
import type {
|
|
5
3
|
Async,
|
|
6
4
|
Blob,
|
|
@@ -8,9 +6,8 @@ import type {
|
|
|
8
6
|
BundleGraph,
|
|
9
7
|
Dependency,
|
|
10
8
|
NamedBundle,
|
|
11
|
-
} from '@atlaspack/types';
|
|
9
|
+
} from '@atlaspack/types-internal';
|
|
12
10
|
import {performStringReplacements} from '@atlaspack/rust';
|
|
13
|
-
import {getFeatureFlag} from '@atlaspack/feature-flags';
|
|
14
11
|
|
|
15
12
|
import {Readable} from 'stream';
|
|
16
13
|
import nullthrows from 'nullthrows';
|
|
@@ -20,7 +17,10 @@ import {bufferStream, relativeBundlePath, urlJoin} from './';
|
|
|
20
17
|
|
|
21
18
|
type ReplacementMap = Map<
|
|
22
19
|
string /* dependency id */,
|
|
23
|
-
{
|
|
20
|
+
{
|
|
21
|
+
from: string;
|
|
22
|
+
to: string;
|
|
23
|
+
}
|
|
24
24
|
>;
|
|
25
25
|
|
|
26
26
|
/*
|
|
@@ -35,18 +35,21 @@ export function replaceURLReferences({
|
|
|
35
35
|
bundleGraph,
|
|
36
36
|
contents,
|
|
37
37
|
map,
|
|
38
|
-
getReplacement = (s) => s,
|
|
38
|
+
getReplacement = (s: string) => s,
|
|
39
39
|
relative = true,
|
|
40
|
-
}: {
|
|
41
|
-
bundle: NamedBundle
|
|
42
|
-
bundleGraph: BundleGraph<NamedBundle
|
|
43
|
-
contents: string
|
|
44
|
-
relative?: boolean
|
|
45
|
-
map?:
|
|
46
|
-
getReplacement?: (string) => string
|
|
47
|
-
|
|
40
|
+
}: {
|
|
41
|
+
bundle: NamedBundle;
|
|
42
|
+
bundleGraph: BundleGraph<NamedBundle>;
|
|
43
|
+
contents: string;
|
|
44
|
+
relative?: boolean;
|
|
45
|
+
map?: SourceMap | null | undefined;
|
|
46
|
+
getReplacement?: (arg1: string) => string;
|
|
47
|
+
}): {
|
|
48
|
+
readonly contents: string;
|
|
49
|
+
readonly map: SourceMap | null | undefined;
|
|
50
|
+
} {
|
|
48
51
|
let replacements = new Map();
|
|
49
|
-
let urlDependencies = [];
|
|
52
|
+
let urlDependencies: Array<Dependency> = [];
|
|
50
53
|
bundle.traverse((node) => {
|
|
51
54
|
if (node.type === 'dependency' && node.value.specifierType === 'url') {
|
|
52
55
|
urlDependencies.push(node.value);
|
|
@@ -70,7 +73,10 @@ export function replaceURLReferences({
|
|
|
70
73
|
continue;
|
|
71
74
|
}
|
|
72
75
|
|
|
73
|
-
if (
|
|
76
|
+
if (
|
|
77
|
+
resolved.bundleBehavior === 'inline' ||
|
|
78
|
+
resolved.bundleBehavior === 'inlineIsolated'
|
|
79
|
+
) {
|
|
74
80
|
// If a bundle is inline, it should be replaced with inline contents,
|
|
75
81
|
// not a URL.
|
|
76
82
|
continue;
|
|
@@ -102,24 +108,32 @@ export async function replaceInlineReferences({
|
|
|
102
108
|
map,
|
|
103
109
|
getInlineReplacement,
|
|
104
110
|
getInlineBundleContents,
|
|
105
|
-
}: {
|
|
106
|
-
bundle: Bundle
|
|
107
|
-
bundleGraph: BundleGraph<NamedBundle
|
|
108
|
-
contents: string
|
|
111
|
+
}: {
|
|
112
|
+
bundle: Bundle;
|
|
113
|
+
bundleGraph: BundleGraph<NamedBundle>;
|
|
114
|
+
contents: string;
|
|
109
115
|
getInlineReplacement: (
|
|
110
|
-
Dependency,
|
|
111
|
-
|
|
112
|
-
string,
|
|
113
|
-
) => {
|
|
116
|
+
arg1: Dependency,
|
|
117
|
+
arg2: 'string' | null | undefined,
|
|
118
|
+
arg3: string,
|
|
119
|
+
) => {
|
|
120
|
+
from: string;
|
|
121
|
+
to: string;
|
|
122
|
+
};
|
|
114
123
|
getInlineBundleContents: (
|
|
115
|
-
Bundle,
|
|
116
|
-
BundleGraph<NamedBundle>,
|
|
117
|
-
) => Async<{
|
|
118
|
-
|
|
119
|
-
|
|
124
|
+
arg1: Bundle,
|
|
125
|
+
arg2: BundleGraph<NamedBundle>,
|
|
126
|
+
) => Async<{
|
|
127
|
+
contents: Blob;
|
|
128
|
+
}>;
|
|
129
|
+
map?: SourceMap | null | undefined;
|
|
130
|
+
}): Promise<{
|
|
131
|
+
readonly contents: string;
|
|
132
|
+
readonly map: SourceMap | null | undefined;
|
|
133
|
+
}> {
|
|
120
134
|
let replacements = new Map();
|
|
121
135
|
|
|
122
|
-
let dependencies = [];
|
|
136
|
+
let dependencies: Array<Dependency> = [];
|
|
123
137
|
bundle.traverse((node) => {
|
|
124
138
|
if (node.type === 'dependency') {
|
|
125
139
|
dependencies.push(node.value);
|
|
@@ -128,7 +142,10 @@ export async function replaceInlineReferences({
|
|
|
128
142
|
|
|
129
143
|
for (let dependency of dependencies) {
|
|
130
144
|
let entryBundle = bundleGraph.getReferencedBundle(dependency, bundle);
|
|
131
|
-
if (
|
|
145
|
+
if (
|
|
146
|
+
entryBundle?.bundleBehavior !== 'inline' &&
|
|
147
|
+
entryBundle?.bundleBehavior !== 'inlineIsolated'
|
|
148
|
+
) {
|
|
132
149
|
continue;
|
|
133
150
|
}
|
|
134
151
|
|
|
@@ -162,13 +179,16 @@ export function getURLReplacement({
|
|
|
162
179
|
toBundle,
|
|
163
180
|
relative,
|
|
164
181
|
getReplacement,
|
|
165
|
-
}: {
|
|
166
|
-
dependency: Dependency
|
|
167
|
-
fromBundle: NamedBundle
|
|
168
|
-
toBundle: NamedBundle
|
|
169
|
-
relative: boolean
|
|
170
|
-
getReplacement?: (string) => string
|
|
171
|
-
|
|
182
|
+
}: {
|
|
183
|
+
dependency: Dependency;
|
|
184
|
+
fromBundle: NamedBundle;
|
|
185
|
+
toBundle: NamedBundle;
|
|
186
|
+
relative: boolean;
|
|
187
|
+
getReplacement?: (arg1: string) => string;
|
|
188
|
+
}): {
|
|
189
|
+
from: string;
|
|
190
|
+
to: string;
|
|
191
|
+
} {
|
|
172
192
|
let to;
|
|
173
193
|
|
|
174
194
|
let orig = URL.parse(dependency.specifier);
|
|
@@ -208,21 +228,17 @@ export function getURLReplacement({
|
|
|
208
228
|
function performReplacement(
|
|
209
229
|
replacements: ReplacementMap,
|
|
210
230
|
contents: string,
|
|
211
|
-
map?:
|
|
212
|
-
): {
|
|
231
|
+
map?: SourceMap | null,
|
|
232
|
+
): {
|
|
233
|
+
readonly contents: string;
|
|
234
|
+
readonly map: SourceMap | null | undefined;
|
|
235
|
+
} {
|
|
213
236
|
let finalContents = contents;
|
|
214
237
|
|
|
215
|
-
|
|
216
|
-
let replacementList = Array.from(replacements.values());
|
|
238
|
+
let replacementList = Array.from(replacements.values());
|
|
217
239
|
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
}
|
|
221
|
-
} else {
|
|
222
|
-
for (let {from, to} of replacements.values()) {
|
|
223
|
-
// Perform replacement
|
|
224
|
-
finalContents = finalContents.split(from).join(to);
|
|
225
|
-
}
|
|
240
|
+
if (replacementList.length > 0) {
|
|
241
|
+
finalContents = performStringReplacements(contents, replacementList);
|
|
226
242
|
}
|
|
227
243
|
|
|
228
244
|
return {
|