@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.
Files changed (197) hide show
  1. package/CHANGELOG.md +462 -0
  2. package/benchmark.js +23 -0
  3. package/dist/DefaultMap.js +41 -0
  4. package/dist/Deferred.js +16 -0
  5. package/dist/PromiseQueue.js +107 -0
  6. package/dist/TapStream.js +23 -0
  7. package/dist/alternatives.js +97 -0
  8. package/dist/ansi-html.js +12 -0
  9. package/dist/blob.js +29 -0
  10. package/dist/bundle-url.js +32 -0
  11. package/dist/collection.js +106 -0
  12. package/dist/config.js +138 -0
  13. package/dist/countLines.js +12 -0
  14. package/dist/debounce.js +15 -0
  15. package/dist/debug-tools.js +39 -0
  16. package/dist/dependency-location.js +22 -0
  17. package/dist/escape-html.js +19 -0
  18. package/dist/generateBuildMetrics.js +111 -0
  19. package/dist/generateCertificate.js +124 -0
  20. package/dist/getCertificate.js +13 -0
  21. package/dist/getExisting.js +20 -0
  22. package/dist/getModuleParts.js +27 -0
  23. package/dist/getRootDir.js +46 -0
  24. package/dist/getTimeId.js +13 -0
  25. package/dist/glob.js +129 -0
  26. package/dist/hash.js +45 -0
  27. package/dist/http-server.js +55 -0
  28. package/dist/index.js +148 -0
  29. package/dist/is-url.js +15 -0
  30. package/dist/isDirectoryInside.js +11 -0
  31. package/dist/objectHash.js +20 -0
  32. package/dist/openInBrowser.js +61 -0
  33. package/dist/parseCSSImport.js +14 -0
  34. package/dist/path.js +36 -0
  35. package/dist/prettifyTime.js +6 -0
  36. package/dist/prettyDiagnostic.js +108 -0
  37. package/dist/progress-message.js +31 -0
  38. package/dist/relativeBundlePath.js +13 -0
  39. package/dist/relativeUrl.js +11 -0
  40. package/dist/replaceBundleReferences.js +131 -0
  41. package/dist/schema.js +404 -0
  42. package/dist/shared-buffer.js +24 -0
  43. package/dist/sourcemap.js +121 -0
  44. package/dist/stream.js +69 -0
  45. package/dist/throttle.js +12 -0
  46. package/dist/urlJoin.js +22 -0
  47. package/lib/DefaultMap.js +42 -0
  48. package/lib/Deferred.js +30 -0
  49. package/lib/PromiseQueue.js +112 -0
  50. package/lib/TapStream.js +34 -0
  51. package/lib/alternatives.js +116 -0
  52. package/lib/ansi-html.js +20 -0
  53. package/lib/blob.js +40 -0
  54. package/lib/bundle-url.js +34 -0
  55. package/lib/collection.js +111 -0
  56. package/lib/config.js +174 -0
  57. package/lib/countLines.js +15 -0
  58. package/lib/debounce.js +18 -0
  59. package/lib/debug-tools.js +40 -0
  60. package/lib/dependency-location.js +21 -0
  61. package/lib/escape-html.js +22 -0
  62. package/lib/generateBuildMetrics.js +121 -0
  63. package/lib/generateCertificate.js +129 -0
  64. package/lib/getCertificate.js +18 -0
  65. package/lib/getExisting.js +25 -0
  66. package/lib/getModuleParts.js +30 -0
  67. package/lib/getRootDir.js +52 -0
  68. package/lib/getTimeId.js +10 -0
  69. package/lib/glob.js +110 -0
  70. package/lib/hash.js +50 -0
  71. package/lib/http-server.js +85 -0
  72. package/lib/index.js +643 -37310
  73. package/lib/is-url.js +24 -0
  74. package/lib/isDirectoryInside.js +18 -0
  75. package/lib/objectHash.js +26 -0
  76. package/lib/openInBrowser.js +74 -0
  77. package/lib/parseCSSImport.js +15 -0
  78. package/lib/path.js +39 -0
  79. package/lib/prettifyTime.js +9 -0
  80. package/lib/prettyDiagnostic.js +154 -0
  81. package/lib/progress-message.js +39 -0
  82. package/lib/relativeBundlePath.js +22 -0
  83. package/lib/relativeUrl.js +24 -0
  84. package/lib/replaceBundleReferences.js +182 -0
  85. package/lib/schema.js +353 -0
  86. package/lib/shared-buffer.js +31 -0
  87. package/lib/sourcemap.js +138 -0
  88. package/lib/stream.js +76 -0
  89. package/lib/throttle.js +15 -0
  90. package/lib/types/DefaultMap.d.ts +13 -0
  91. package/lib/types/Deferred.d.ts +8 -0
  92. package/lib/types/PromiseQueue.d.ts +25 -0
  93. package/lib/types/TapStream.d.ts +6 -0
  94. package/lib/types/alternatives.d.ts +3 -0
  95. package/lib/types/ansi-html.d.ts +1 -0
  96. package/lib/types/blob.d.ts +4 -0
  97. package/lib/types/bundle-url.d.ts +4 -0
  98. package/lib/types/collection.d.ts +33 -0
  99. package/lib/types/config.d.ts +17 -0
  100. package/lib/types/countLines.d.ts +1 -0
  101. package/lib/types/debounce.d.ts +1 -0
  102. package/lib/types/debug-tools.d.ts +8 -0
  103. package/lib/types/dependency-location.d.ts +14 -0
  104. package/lib/types/escape-html.d.ts +1 -0
  105. package/lib/types/generateBuildMetrics.d.ts +18 -0
  106. package/lib/types/generateCertificate.d.ts +5 -0
  107. package/lib/types/getCertificate.d.ts +5 -0
  108. package/lib/types/getExisting.d.ts +8 -0
  109. package/lib/types/getModuleParts.d.ts +4 -0
  110. package/lib/types/getRootDir.d.ts +2 -0
  111. package/lib/types/getTimeId.d.ts +1 -0
  112. package/lib/types/glob.d.ts +9 -0
  113. package/lib/types/hash.d.ts +7 -0
  114. package/lib/types/http-server.d.ts +19 -0
  115. package/lib/types/index.d.ts +49 -0
  116. package/lib/types/is-url.d.ts +1 -0
  117. package/lib/types/isDirectoryInside.d.ts +2 -0
  118. package/lib/types/objectHash.d.ts +3 -0
  119. package/lib/types/openInBrowser.d.ts +1 -0
  120. package/lib/types/parseCSSImport.d.ts +1 -0
  121. package/lib/types/path.d.ts +8 -0
  122. package/lib/types/prettifyTime.d.ts +1 -0
  123. package/lib/types/prettyDiagnostic.d.ts +18 -0
  124. package/lib/types/progress-message.d.ts +3 -0
  125. package/lib/types/relativeBundlePath.d.ts +4 -0
  126. package/lib/types/relativeUrl.d.ts +1 -0
  127. package/lib/types/replaceBundleReferences.d.ts +39 -0
  128. package/lib/types/schema.d.ts +107 -0
  129. package/lib/types/shared-buffer.d.ts +2 -0
  130. package/lib/types/sourcemap.d.ts +15 -0
  131. package/lib/types/stream.d.ts +8 -0
  132. package/lib/types/throttle.d.ts +1 -0
  133. package/lib/types/urlJoin.d.ts +5 -0
  134. package/lib/urlJoin.js +35 -0
  135. package/package.json +27 -18
  136. package/src/{DefaultMap.js → DefaultMap.ts} +8 -12
  137. package/src/Deferred.ts +26 -0
  138. package/src/{PromiseQueue.js → PromiseQueue.ts} +40 -35
  139. package/src/{TapStream.js → TapStream.ts} +8 -7
  140. package/src/{alternatives.js → alternatives.ts} +15 -16
  141. package/src/{ansi-html.js → ansi-html.ts} +1 -1
  142. package/src/{blob.js → blob.ts} +3 -5
  143. package/src/{bundle-url.js → bundle-url.ts} +3 -5
  144. package/src/{collection.js → collection.ts} +23 -20
  145. package/src/{config.js → config.ts} +20 -21
  146. package/src/{countLines.js → countLines.ts} +0 -2
  147. package/src/{debounce.js → debounce.ts} +3 -5
  148. package/src/debug-tools.ts +48 -0
  149. package/src/{dependency-location.js → dependency-location.ts} +15 -11
  150. package/src/{escape-html.js → escape-html.ts} +5 -3
  151. package/src/{generateBuildMetrics.js → generateBuildMetrics.ts} +19 -21
  152. package/src/{generateCertificate.js → generateCertificate.ts} +8 -6
  153. package/src/{getCertificate.js → getCertificate.ts} +6 -5
  154. package/src/{getExisting.js → getExisting.ts} +4 -3
  155. package/src/{getModuleParts.js → getModuleParts.ts} +3 -2
  156. package/src/{getRootDir.js → getRootDir.ts} +1 -3
  157. package/src/getTimeId.ts +12 -0
  158. package/src/{glob.js → glob.ts} +13 -14
  159. package/src/{hash.js → hash.ts} +23 -18
  160. package/src/{http-server.js → http-server.ts} +34 -40
  161. package/src/{index.js → index.ts} +14 -10
  162. package/src/{is-url.js → is-url.ts} +1 -2
  163. package/src/{isDirectoryInside.js → isDirectoryInside.ts} +1 -2
  164. package/src/{objectHash.js → objectHash.ts} +1 -4
  165. package/src/{openInBrowser.js → openInBrowser.ts} +2 -4
  166. package/src/{parseCSSImport.js → parseCSSImport.ts} +0 -2
  167. package/src/{path.js → path.ts} +2 -4
  168. package/src/{prettifyTime.js → prettifyTime.ts} +0 -2
  169. package/src/{prettyDiagnostic.js → prettyDiagnostic.ts} +47 -24
  170. package/src/progress-message.ts +43 -0
  171. package/src/{relativeBundlePath.js → relativeBundlePath.ts} +4 -4
  172. package/src/{relativeUrl.js → relativeUrl.ts} +0 -1
  173. package/src/{replaceBundleReferences.js → replaceBundleReferences.ts} +67 -51
  174. package/src/schema.ts +552 -0
  175. package/src/{shared-buffer.js → shared-buffer.ts} +5 -3
  176. package/src/{sourcemap.js → sourcemap.ts} +28 -10
  177. package/src/{stream.js → stream.ts} +30 -22
  178. package/src/throttle.ts +13 -0
  179. package/src/{urlJoin.js → urlJoin.ts} +1 -3
  180. package/test/{DefaultMap.test.js → DefaultMap.test.ts} +4 -6
  181. package/test/{PromiseQueue.test.js → PromiseQueue.test.ts} +5 -6
  182. package/test/{collection.test.js → collection.test.ts} +0 -2
  183. package/test/{config.test.js → config.test.ts} +0 -3
  184. package/test/{objectHash.test.js → objectHash.test.ts} +4 -5
  185. package/test/{prettifyTime.test.js → prettifyTime.test.ts} +0 -1
  186. package/test/{replaceBundleReferences.test.js → replaceBundleReferences.test.ts} +0 -32
  187. package/test/schema.test.ts +748 -0
  188. package/test/{sourcemap.test.js → sourcemap.test.ts} +0 -1
  189. package/test/{throttle.test.js → throttle.test.ts} +1 -3
  190. package/test/{urlJoin.test.js → urlJoin.test.ts} +0 -2
  191. package/tsconfig.json +36 -0
  192. package/tsconfig.tsbuildinfo +1 -0
  193. package/lib/index.js.map +0 -1
  194. package/src/Deferred.js +0 -23
  195. package/src/progress-message.js +0 -22
  196. package/src/schema.js +0 -504
  197. 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 default async function prettyDiagnostic(
31
+ export function prettyDiagnosticSync(
34
32
  diagnostic: Diagnostic,
35
33
  options?: PluginOptions,
36
34
  terminalWidth?: number,
37
35
  format: 'ansi' | 'html' = 'ansi',
38
- ): Promise<AnsiDiagnosticResult> {
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
- (text, url, _) => `<a href="${url}">${text}</a>`;
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
- code = await options.inputFS.readFile(filePath, 'utf8');
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
- // @flow strict-local
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: {|leadingDotSlash: boolean|} = {leadingDotSlash: true},
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,4 +1,3 @@
1
- // @flow
2
1
  import path from 'path';
3
2
  import url from 'url';
4
3
 
@@ -1,6 +1,4 @@
1
- // @flow strict-local
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
- {|from: string, to: string|},
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?: ?SourceMap,
46
- getReplacement?: (string) => string,
47
- |}): {|+contents: string, +map: ?SourceMap|} {
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 (resolved.bundleBehavior === 'inline') {
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
- ?'string',
112
- string,
113
- ) => {|from: string, to: string|},
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<{|contents: Blob|}>,
118
- map?: ?SourceMap,
119
- |}): Promise<{|+contents: string, +map: ?SourceMap|}> {
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 (entryBundle?.bundleBehavior !== 'inline') {
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
- |}): {|from: string, to: string|} {
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?: ?SourceMap,
212
- ): {|+contents: string, +map: ?SourceMap|} {
231
+ map?: SourceMap | null,
232
+ ): {
233
+ readonly contents: string;
234
+ readonly map: SourceMap | null | undefined;
235
+ } {
213
236
  let finalContents = contents;
214
237
 
215
- if (getFeatureFlag('inlineStringReplacementPerf')) {
216
- let replacementList = Array.from(replacements.values());
238
+ let replacementList = Array.from(replacements.values());
217
239
 
218
- if (replacementList.length > 0) {
219
- finalContents = performStringReplacements(contents, replacementList);
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 {