@atlaspack/utils 2.14.5-canary.27 → 2.14.5-canary.271

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 (193) hide show
  1. package/CHANGELOG.md +326 -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/glob.js +129 -0
  25. package/dist/hash.js +45 -0
  26. package/dist/http-server.js +55 -0
  27. package/dist/index.js +146 -0
  28. package/dist/is-url.js +15 -0
  29. package/dist/isDirectoryInside.js +11 -0
  30. package/dist/objectHash.js +20 -0
  31. package/dist/openInBrowser.js +61 -0
  32. package/dist/parseCSSImport.js +14 -0
  33. package/dist/path.js +36 -0
  34. package/dist/prettifyTime.js +6 -0
  35. package/dist/prettyDiagnostic.js +104 -0
  36. package/dist/progress-message.js +31 -0
  37. package/dist/relativeBundlePath.js +13 -0
  38. package/dist/relativeUrl.js +11 -0
  39. package/dist/replaceBundleReferences.js +131 -0
  40. package/dist/schema.js +404 -0
  41. package/dist/shared-buffer.js +24 -0
  42. package/dist/sourcemap.js +121 -0
  43. package/dist/stream.js +69 -0
  44. package/dist/throttle.js +12 -0
  45. package/dist/urlJoin.js +22 -0
  46. package/lib/DefaultMap.js +42 -0
  47. package/lib/Deferred.js +30 -0
  48. package/lib/PromiseQueue.js +112 -0
  49. package/lib/TapStream.js +34 -0
  50. package/lib/alternatives.js +116 -0
  51. package/lib/ansi-html.js +20 -0
  52. package/lib/blob.js +40 -0
  53. package/lib/bundle-url.js +34 -0
  54. package/lib/collection.js +111 -0
  55. package/lib/config.js +174 -0
  56. package/lib/countLines.js +15 -0
  57. package/lib/debounce.js +18 -0
  58. package/lib/debug-tools.js +40 -0
  59. package/lib/dependency-location.js +21 -0
  60. package/lib/escape-html.js +22 -0
  61. package/lib/generateBuildMetrics.js +121 -0
  62. package/lib/generateCertificate.js +129 -0
  63. package/lib/getCertificate.js +18 -0
  64. package/lib/getExisting.js +25 -0
  65. package/lib/getModuleParts.js +30 -0
  66. package/lib/getRootDir.js +52 -0
  67. package/lib/glob.js +110 -0
  68. package/lib/hash.js +50 -0
  69. package/lib/http-server.js +85 -0
  70. package/lib/index.js +635 -37310
  71. package/lib/is-url.js +24 -0
  72. package/lib/isDirectoryInside.js +18 -0
  73. package/lib/objectHash.js +26 -0
  74. package/lib/openInBrowser.js +74 -0
  75. package/lib/parseCSSImport.js +15 -0
  76. package/lib/path.js +39 -0
  77. package/lib/prettifyTime.js +9 -0
  78. package/lib/prettyDiagnostic.js +150 -0
  79. package/lib/progress-message.js +39 -0
  80. package/lib/relativeBundlePath.js +22 -0
  81. package/lib/relativeUrl.js +24 -0
  82. package/lib/replaceBundleReferences.js +182 -0
  83. package/lib/schema.js +353 -0
  84. package/lib/shared-buffer.js +31 -0
  85. package/lib/sourcemap.js +138 -0
  86. package/lib/stream.js +76 -0
  87. package/lib/throttle.js +15 -0
  88. package/lib/types/DefaultMap.d.ts +13 -0
  89. package/lib/types/Deferred.d.ts +8 -0
  90. package/lib/types/PromiseQueue.d.ts +25 -0
  91. package/lib/types/TapStream.d.ts +6 -0
  92. package/lib/types/alternatives.d.ts +3 -0
  93. package/lib/types/ansi-html.d.ts +1 -0
  94. package/lib/types/blob.d.ts +4 -0
  95. package/lib/types/bundle-url.d.ts +4 -0
  96. package/lib/types/collection.d.ts +33 -0
  97. package/lib/types/config.d.ts +17 -0
  98. package/lib/types/countLines.d.ts +1 -0
  99. package/lib/types/debounce.d.ts +1 -0
  100. package/lib/types/debug-tools.d.ts +8 -0
  101. package/lib/types/dependency-location.d.ts +14 -0
  102. package/lib/types/escape-html.d.ts +1 -0
  103. package/lib/types/generateBuildMetrics.d.ts +18 -0
  104. package/lib/types/generateCertificate.d.ts +5 -0
  105. package/lib/types/getCertificate.d.ts +5 -0
  106. package/lib/types/getExisting.d.ts +8 -0
  107. package/lib/types/getModuleParts.d.ts +4 -0
  108. package/lib/types/getRootDir.d.ts +2 -0
  109. package/lib/types/glob.d.ts +9 -0
  110. package/lib/types/hash.d.ts +7 -0
  111. package/lib/types/http-server.d.ts +19 -0
  112. package/lib/types/index.d.ts +48 -0
  113. package/lib/types/is-url.d.ts +1 -0
  114. package/lib/types/isDirectoryInside.d.ts +2 -0
  115. package/lib/types/objectHash.d.ts +3 -0
  116. package/lib/types/openInBrowser.d.ts +1 -0
  117. package/lib/types/parseCSSImport.d.ts +1 -0
  118. package/lib/types/path.d.ts +8 -0
  119. package/lib/types/prettifyTime.d.ts +1 -0
  120. package/lib/types/prettyDiagnostic.d.ts +17 -0
  121. package/lib/types/progress-message.d.ts +3 -0
  122. package/lib/types/relativeBundlePath.d.ts +4 -0
  123. package/lib/types/relativeUrl.d.ts +1 -0
  124. package/lib/types/replaceBundleReferences.d.ts +39 -0
  125. package/lib/types/schema.d.ts +107 -0
  126. package/lib/types/shared-buffer.d.ts +2 -0
  127. package/lib/types/sourcemap.d.ts +15 -0
  128. package/lib/types/stream.d.ts +8 -0
  129. package/lib/types/throttle.d.ts +1 -0
  130. package/lib/types/urlJoin.d.ts +5 -0
  131. package/lib/urlJoin.js +35 -0
  132. package/package.json +26 -17
  133. package/src/{DefaultMap.js → DefaultMap.ts} +8 -12
  134. package/src/Deferred.ts +26 -0
  135. package/src/{PromiseQueue.js → PromiseQueue.ts} +40 -35
  136. package/src/{TapStream.js → TapStream.ts} +8 -7
  137. package/src/{alternatives.js → alternatives.ts} +15 -16
  138. package/src/{ansi-html.js → ansi-html.ts} +1 -1
  139. package/src/{blob.js → blob.ts} +3 -5
  140. package/src/{bundle-url.js → bundle-url.ts} +3 -5
  141. package/src/{collection.js → collection.ts} +23 -20
  142. package/src/{config.js → config.ts} +20 -21
  143. package/src/{countLines.js → countLines.ts} +0 -2
  144. package/src/{debounce.js → debounce.ts} +3 -5
  145. package/src/debug-tools.ts +48 -0
  146. package/src/{dependency-location.js → dependency-location.ts} +15 -11
  147. package/src/{escape-html.js → escape-html.ts} +5 -3
  148. package/src/{generateBuildMetrics.js → generateBuildMetrics.ts} +18 -20
  149. package/src/{generateCertificate.js → generateCertificate.ts} +8 -6
  150. package/src/{getCertificate.js → getCertificate.ts} +6 -5
  151. package/src/{getExisting.js → getExisting.ts} +4 -3
  152. package/src/{getModuleParts.js → getModuleParts.ts} +3 -2
  153. package/src/{getRootDir.js → getRootDir.ts} +1 -3
  154. package/src/{glob.js → glob.ts} +13 -14
  155. package/src/{hash.js → hash.ts} +23 -18
  156. package/src/{http-server.js → http-server.ts} +34 -40
  157. package/src/{index.js → index.ts} +13 -9
  158. package/src/{is-url.js → is-url.ts} +1 -2
  159. package/src/{isDirectoryInside.js → isDirectoryInside.ts} +1 -2
  160. package/src/{objectHash.js → objectHash.ts} +1 -4
  161. package/src/{openInBrowser.js → openInBrowser.ts} +2 -4
  162. package/src/{parseCSSImport.js → parseCSSImport.ts} +0 -2
  163. package/src/{path.js → path.ts} +2 -4
  164. package/src/{prettifyTime.js → prettifyTime.ts} +0 -2
  165. package/src/{prettyDiagnostic.js → prettyDiagnostic.ts} +34 -22
  166. package/src/progress-message.ts +43 -0
  167. package/src/{relativeBundlePath.js → relativeBundlePath.ts} +4 -4
  168. package/src/{relativeUrl.js → relativeUrl.ts} +0 -1
  169. package/src/{replaceBundleReferences.js → replaceBundleReferences.ts} +66 -50
  170. package/src/schema.ts +552 -0
  171. package/src/{shared-buffer.js → shared-buffer.ts} +5 -3
  172. package/src/{sourcemap.js → sourcemap.ts} +27 -9
  173. package/src/{stream.js → stream.ts} +30 -22
  174. package/src/throttle.ts +13 -0
  175. package/src/{urlJoin.js → urlJoin.ts} +1 -3
  176. package/test/{DefaultMap.test.js → DefaultMap.test.ts} +4 -6
  177. package/test/{PromiseQueue.test.js → PromiseQueue.test.ts} +5 -6
  178. package/test/{collection.test.js → collection.test.ts} +0 -2
  179. package/test/{config.test.js → config.test.ts} +0 -3
  180. package/test/{objectHash.test.js → objectHash.test.ts} +4 -5
  181. package/test/{prettifyTime.test.js → prettifyTime.test.ts} +0 -1
  182. package/test/{replaceBundleReferences.test.js → replaceBundleReferences.test.ts} +0 -32
  183. package/test/schema.test.ts +748 -0
  184. package/test/{sourcemap.test.js → sourcemap.test.ts} +0 -1
  185. package/test/{throttle.test.js → throttle.test.ts} +1 -3
  186. package/test/{urlJoin.test.js → urlJoin.test.ts} +0 -2
  187. package/tsconfig.json +33 -0
  188. package/tsconfig.tsbuildinfo +1 -0
  189. package/lib/index.js.map +0 -1
  190. package/src/Deferred.js +0 -23
  191. package/src/progress-message.js +0 -22
  192. package/src/schema.js +0 -504
  193. package/src/throttle.js +0 -15
@@ -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,5 +1,3 @@
1
- // @flow strict-local
2
-
3
1
  import type SourceMap from '@parcel/source-map';
4
2
  import type {
5
3
  Async,
@@ -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 {