@atlaspack/utils 2.14.5-canary.22 → 2.14.5-canary.221

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 (191) hide show
  1. package/CHANGELOG.md +294 -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 +38 -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 +140 -0
  40. package/dist/schema.js +389 -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 +39 -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 +199 -0
  83. package/lib/schema.js +355 -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 +7 -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 +46 -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} +63 -39
  170. package/src/{schema.js → schema.ts} +158 -141
  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/{sourcemap.test.js → sourcemap.test.ts} +0 -1
  184. package/test/{throttle.test.js → throttle.test.ts} +1 -3
  185. package/test/{urlJoin.test.js → urlJoin.test.ts} +0 -2
  186. package/tsconfig.json +33 -0
  187. package/tsconfig.tsbuildinfo +1 -0
  188. package/lib/index.js.map +0 -1
  189. package/src/Deferred.js +0 -23
  190. package/src/progress-message.js +0 -22
  191. 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,7 +6,7 @@ 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
11
  import {getFeatureFlag} from '@atlaspack/feature-flags';
14
12
 
@@ -20,7 +18,10 @@ import {bufferStream, relativeBundlePath, urlJoin} from './';
20
18
 
21
19
  type ReplacementMap = Map<
22
20
  string /* dependency id */,
23
- {|from: string, to: string|},
21
+ {
22
+ from: string;
23
+ to: string;
24
+ }
24
25
  >;
25
26
 
26
27
  /*
@@ -35,18 +36,21 @@ export function replaceURLReferences({
35
36
  bundleGraph,
36
37
  contents,
37
38
  map,
38
- getReplacement = (s) => s,
39
+ getReplacement = (s: string) => s,
39
40
  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|} {
41
+ }: {
42
+ bundle: NamedBundle;
43
+ bundleGraph: BundleGraph<NamedBundle>;
44
+ contents: string;
45
+ relative?: boolean;
46
+ map?: SourceMap | null | undefined;
47
+ getReplacement?: (arg1: string) => string;
48
+ }): {
49
+ readonly contents: string;
50
+ readonly map: SourceMap | null | undefined;
51
+ } {
48
52
  let replacements = new Map();
49
- let urlDependencies = [];
53
+ let urlDependencies: Array<Dependency> = [];
50
54
  bundle.traverse((node) => {
51
55
  if (node.type === 'dependency' && node.value.specifierType === 'url') {
52
56
  urlDependencies.push(node.value);
@@ -70,7 +74,10 @@ export function replaceURLReferences({
70
74
  continue;
71
75
  }
72
76
 
73
- if (resolved.bundleBehavior === 'inline') {
77
+ if (
78
+ resolved.bundleBehavior === 'inline' ||
79
+ resolved.bundleBehavior === 'inlineIsolated'
80
+ ) {
74
81
  // If a bundle is inline, it should be replaced with inline contents,
75
82
  // not a URL.
76
83
  continue;
@@ -102,24 +109,32 @@ export async function replaceInlineReferences({
102
109
  map,
103
110
  getInlineReplacement,
104
111
  getInlineBundleContents,
105
- }: {|
106
- bundle: Bundle,
107
- bundleGraph: BundleGraph<NamedBundle>,
108
- contents: string,
112
+ }: {
113
+ bundle: Bundle;
114
+ bundleGraph: BundleGraph<NamedBundle>;
115
+ contents: string;
109
116
  getInlineReplacement: (
110
- Dependency,
111
- ?'string',
112
- string,
113
- ) => {|from: string, to: string|},
117
+ arg1: Dependency,
118
+ arg2: 'string' | null | undefined,
119
+ arg3: string,
120
+ ) => {
121
+ from: string;
122
+ to: string;
123
+ };
114
124
  getInlineBundleContents: (
115
- Bundle,
116
- BundleGraph<NamedBundle>,
117
- ) => Async<{|contents: Blob|}>,
118
- map?: ?SourceMap,
119
- |}): Promise<{|+contents: string, +map: ?SourceMap|}> {
125
+ arg1: Bundle,
126
+ arg2: BundleGraph<NamedBundle>,
127
+ ) => Async<{
128
+ contents: Blob;
129
+ }>;
130
+ map?: SourceMap | null | undefined;
131
+ }): Promise<{
132
+ readonly contents: string;
133
+ readonly map: SourceMap | null | undefined;
134
+ }> {
120
135
  let replacements = new Map();
121
136
 
122
- let dependencies = [];
137
+ let dependencies: Array<Dependency> = [];
123
138
  bundle.traverse((node) => {
124
139
  if (node.type === 'dependency') {
125
140
  dependencies.push(node.value);
@@ -128,7 +143,10 @@ export async function replaceInlineReferences({
128
143
 
129
144
  for (let dependency of dependencies) {
130
145
  let entryBundle = bundleGraph.getReferencedBundle(dependency, bundle);
131
- if (entryBundle?.bundleBehavior !== 'inline') {
146
+ if (
147
+ entryBundle?.bundleBehavior !== 'inline' &&
148
+ entryBundle?.bundleBehavior !== 'inlineIsolated'
149
+ ) {
132
150
  continue;
133
151
  }
134
152
 
@@ -162,13 +180,16 @@ export function getURLReplacement({
162
180
  toBundle,
163
181
  relative,
164
182
  getReplacement,
165
- }: {|
166
- dependency: Dependency,
167
- fromBundle: NamedBundle,
168
- toBundle: NamedBundle,
169
- relative: boolean,
170
- getReplacement?: (string) => string,
171
- |}): {|from: string, to: string|} {
183
+ }: {
184
+ dependency: Dependency;
185
+ fromBundle: NamedBundle;
186
+ toBundle: NamedBundle;
187
+ relative: boolean;
188
+ getReplacement?: (arg1: string) => string;
189
+ }): {
190
+ from: string;
191
+ to: string;
192
+ } {
172
193
  let to;
173
194
 
174
195
  let orig = URL.parse(dependency.specifier);
@@ -208,8 +229,11 @@ export function getURLReplacement({
208
229
  function performReplacement(
209
230
  replacements: ReplacementMap,
210
231
  contents: string,
211
- map?: ?SourceMap,
212
- ): {|+contents: string, +map: ?SourceMap|} {
232
+ map?: SourceMap | null,
233
+ ): {
234
+ readonly contents: string;
235
+ readonly map: SourceMap | null | undefined;
236
+ } {
213
237
  let finalContents = contents;
214
238
 
215
239
  if (getFeatureFlag('inlineStringReplacementPerf')) {