@atlaspack/core 2.12.1-canary.3354

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 (215) hide show
  1. package/LICENSE +201 -0
  2. package/index.d.ts +22 -0
  3. package/lib/AssetGraph.js +518 -0
  4. package/lib/Atlaspack.js +587 -0
  5. package/lib/AtlaspackConfig.js +298 -0
  6. package/lib/AtlaspackConfig.schema.js +125 -0
  7. package/lib/BundleGraph.js +1445 -0
  8. package/lib/CommittedAsset.js +133 -0
  9. package/lib/Dependency.js +88 -0
  10. package/lib/Environment.js +128 -0
  11. package/lib/InternalConfig.js +48 -0
  12. package/lib/PackagerRunner.js +519 -0
  13. package/lib/ReporterRunner.js +151 -0
  14. package/lib/RequestTracker.js +1089 -0
  15. package/lib/SymbolPropagation.js +625 -0
  16. package/lib/TargetDescriptor.schema.js +115 -0
  17. package/lib/Transformation.js +536 -0
  18. package/lib/UncommittedAsset.js +342 -0
  19. package/lib/Validation.js +215 -0
  20. package/lib/applyRuntimes.js +279 -0
  21. package/lib/assetUtils.js +189 -0
  22. package/lib/atlaspack-v3/AtlaspackV3.js +74 -0
  23. package/lib/atlaspack-v3/fs.js +30 -0
  24. package/lib/atlaspack-v3/index.js +19 -0
  25. package/lib/atlaspack-v3/jsCallable.js +15 -0
  26. package/lib/atlaspack-v3/plugins/Resolver.js +12 -0
  27. package/lib/atlaspack-v3/plugins/index.js +16 -0
  28. package/lib/atlaspack-v3/worker/index.js +3 -0
  29. package/lib/atlaspack-v3/worker/worker.js +30 -0
  30. package/lib/buildCache.js +18 -0
  31. package/lib/constants.js +21 -0
  32. package/lib/dumpGraphToGraphViz.js +206 -0
  33. package/lib/index.js +106 -0
  34. package/lib/loadAtlaspackPlugin.js +148 -0
  35. package/lib/loadDotEnv.js +54 -0
  36. package/lib/projectPath.js +86 -0
  37. package/lib/public/Asset.js +259 -0
  38. package/lib/public/Bundle.js +231 -0
  39. package/lib/public/BundleGraph.js +193 -0
  40. package/lib/public/BundleGroup.js +44 -0
  41. package/lib/public/Config.js +202 -0
  42. package/lib/public/Dependency.js +131 -0
  43. package/lib/public/Environment.js +244 -0
  44. package/lib/public/MutableBundleGraph.js +184 -0
  45. package/lib/public/PluginOptions.js +71 -0
  46. package/lib/public/Symbols.js +247 -0
  47. package/lib/public/Target.js +64 -0
  48. package/lib/registerCoreWithSerializer.js +45 -0
  49. package/lib/requests/AssetGraphRequest.js +427 -0
  50. package/lib/requests/AssetGraphRequestRust.js +187 -0
  51. package/lib/requests/AssetRequest.js +137 -0
  52. package/lib/requests/AtlaspackBuildRequest.js +78 -0
  53. package/lib/requests/AtlaspackConfigRequest.js +473 -0
  54. package/lib/requests/BundleGraphRequest.js +419 -0
  55. package/lib/requests/ConfigRequest.js +198 -0
  56. package/lib/requests/DevDepRequest.js +166 -0
  57. package/lib/requests/EntryRequest.js +295 -0
  58. package/lib/requests/PackageRequest.js +88 -0
  59. package/lib/requests/PathRequest.js +349 -0
  60. package/lib/requests/TargetRequest.js +1177 -0
  61. package/lib/requests/ValidationRequest.js +66 -0
  62. package/lib/requests/WriteBundleRequest.js +252 -0
  63. package/lib/requests/WriteBundlesRequest.js +153 -0
  64. package/lib/resolveOptions.js +234 -0
  65. package/lib/serializer.js +216 -0
  66. package/lib/serializerCore.browser.js +29 -0
  67. package/lib/serializerCore.js +16 -0
  68. package/lib/summarizeRequest.js +55 -0
  69. package/lib/types.js +35 -0
  70. package/lib/utils.js +160 -0
  71. package/lib/worker.js +170 -0
  72. package/package.json +59 -0
  73. package/src/AssetGraph.js +646 -0
  74. package/src/Atlaspack.js +632 -0
  75. package/src/AtlaspackConfig.js +490 -0
  76. package/src/AtlaspackConfig.schema.js +141 -0
  77. package/src/BundleGraph.js +2193 -0
  78. package/src/CommittedAsset.js +143 -0
  79. package/src/Dependency.js +142 -0
  80. package/src/Environment.js +151 -0
  81. package/src/InternalConfig.js +72 -0
  82. package/src/PackagerRunner.js +790 -0
  83. package/src/ReporterRunner.js +158 -0
  84. package/src/RequestTracker.js +1697 -0
  85. package/src/SymbolPropagation.js +794 -0
  86. package/src/TargetDescriptor.schema.js +136 -0
  87. package/src/Transformation.js +752 -0
  88. package/src/UncommittedAsset.js +426 -0
  89. package/src/Validation.js +223 -0
  90. package/src/applyRuntimes.js +341 -0
  91. package/src/assetUtils.js +254 -0
  92. package/src/atlaspack-v3/AtlaspackV3.js +73 -0
  93. package/src/atlaspack-v3/fs.js +36 -0
  94. package/src/atlaspack-v3/index.js +5 -0
  95. package/src/atlaspack-v3/jsCallable.js +13 -0
  96. package/src/atlaspack-v3/plugins/Resolver.js +9 -0
  97. package/src/atlaspack-v3/plugins/index.js +3 -0
  98. package/src/atlaspack-v3/worker/index.js +8 -0
  99. package/src/atlaspack-v3/worker/worker.js +14 -0
  100. package/src/buildCache.js +15 -0
  101. package/src/constants.js +22 -0
  102. package/src/dumpGraphToGraphViz.js +244 -0
  103. package/src/index.js +22 -0
  104. package/src/loadAtlaspackPlugin.js +239 -0
  105. package/src/loadDotEnv.js +56 -0
  106. package/src/projectPath.js +87 -0
  107. package/src/public/Asset.js +359 -0
  108. package/src/public/Bundle.js +337 -0
  109. package/src/public/BundleGraph.js +335 -0
  110. package/src/public/BundleGroup.js +55 -0
  111. package/src/public/Config.js +261 -0
  112. package/src/public/Dependency.js +176 -0
  113. package/src/public/Environment.js +316 -0
  114. package/src/public/MutableBundleGraph.js +320 -0
  115. package/src/public/PluginOptions.js +99 -0
  116. package/src/public/Symbols.js +315 -0
  117. package/src/public/Target.js +71 -0
  118. package/src/registerCoreWithSerializer.js +34 -0
  119. package/src/requests/AssetGraphRequest.js +577 -0
  120. package/src/requests/AssetGraphRequestRust.js +222 -0
  121. package/src/requests/AssetRequest.js +179 -0
  122. package/src/requests/AtlaspackBuildRequest.js +109 -0
  123. package/src/requests/AtlaspackConfigRequest.js +709 -0
  124. package/src/requests/BundleGraphRequest.js +547 -0
  125. package/src/requests/ConfigRequest.js +287 -0
  126. package/src/requests/DevDepRequest.js +246 -0
  127. package/src/requests/EntryRequest.js +385 -0
  128. package/src/requests/PackageRequest.js +105 -0
  129. package/src/requests/PathRequest.js +454 -0
  130. package/src/requests/TargetRequest.js +1632 -0
  131. package/src/requests/ValidationRequest.js +79 -0
  132. package/src/requests/WriteBundleRequest.js +362 -0
  133. package/src/requests/WriteBundlesRequest.js +209 -0
  134. package/src/resolveOptions.js +278 -0
  135. package/src/serializer.js +255 -0
  136. package/src/serializerCore.browser.js +8 -0
  137. package/src/serializerCore.js +5 -0
  138. package/src/summarizeRequest.js +47 -0
  139. package/src/types.js +581 -0
  140. package/src/utils.js +211 -0
  141. package/src/worker.js +189 -0
  142. package/test/AssetGraph.test.js +679 -0
  143. package/test/Atlaspack.test.js +142 -0
  144. package/test/AtlaspackConfig.test.js +405 -0
  145. package/test/AtlaspackConfigRequest.test.js +993 -0
  146. package/test/BundleGraph.test.js +121 -0
  147. package/test/EntryRequest.test.js +215 -0
  148. package/test/Environment.test.js +99 -0
  149. package/test/InternalAsset.test.js +76 -0
  150. package/test/PackagerRunner.test.js +27 -0
  151. package/test/PublicAsset.test.js +40 -0
  152. package/test/PublicBundle.test.js +68 -0
  153. package/test/PublicDependency.test.js +22 -0
  154. package/test/PublicEnvironment.test.js +27 -0
  155. package/test/PublicMutableBundleGraph.test.js +192 -0
  156. package/test/RequestTracker.test.js +448 -0
  157. package/test/SymbolPropagation.test.js +716 -0
  158. package/test/TargetRequest.test.js +1715 -0
  159. package/test/fixtures/application-targets/package.json +3 -0
  160. package/test/fixtures/atlaspack/index.js +1 -0
  161. package/test/fixtures/atlaspack/other.js +3 -0
  162. package/test/fixtures/atlaspack/package.json +1 -0
  163. package/test/fixtures/atlaspack/yarn.lock +0 -0
  164. package/test/fixtures/bundle.js +10 -0
  165. package/test/fixtures/common-targets/package.json +24 -0
  166. package/test/fixtures/common-targets-ignore/package.json +13 -0
  167. package/test/fixtures/config/.atlaspackrc +6 -0
  168. package/test/fixtures/config/subfolder/.atlaspackrc +6 -0
  169. package/test/fixtures/config-extends-not-found/.atlaspackrc +3 -0
  170. package/test/fixtures/config-extends-not-found/.atlaspackrc-json5 +3 -0
  171. package/test/fixtures/config-extends-not-found/.atlaspackrc-multiple +3 -0
  172. package/test/fixtures/config-extends-not-found/.atlaspackrc-node-modules +3 -0
  173. package/test/fixtures/config-malformed/.atlaspackrc +3 -0
  174. package/test/fixtures/config-node-pipeline/.atlaspackrc +6 -0
  175. package/test/fixtures/config-plugin-not-found/.atlaspackrc +6 -0
  176. package/test/fixtures/context/package.json +8 -0
  177. package/test/fixtures/custom-format-infer-ext/package.json +6 -0
  178. package/test/fixtures/custom-format-infer-type/package.json +7 -0
  179. package/test/fixtures/custom-format-mismatch/package.json +8 -0
  180. package/test/fixtures/custom-targets/package.json +20 -0
  181. package/test/fixtures/custom-targets-distdir/package.json +11 -0
  182. package/test/fixtures/duplicate-targets/package.json +4 -0
  183. package/test/fixtures/glob-like/[entry].js +0 -0
  184. package/test/fixtures/invalid-distpath/package.json +11 -0
  185. package/test/fixtures/invalid-engines/package.json +12 -0
  186. package/test/fixtures/invalid-source-missing/package.json +5 -0
  187. package/test/fixtures/invalid-source-not-file/package.json +5 -0
  188. package/test/fixtures/invalid-source-not-file/src/index.js +1 -0
  189. package/test/fixtures/invalid-target-source-missing/package.json +9 -0
  190. package/test/fixtures/invalid-target-source-not-file/package.json +9 -0
  191. package/test/fixtures/invalid-target-source-not-file/src/index.js +1 -0
  192. package/test/fixtures/invalid-targets/package.json +19 -0
  193. package/test/fixtures/library-custom-scopehoist/package.json +9 -0
  194. package/test/fixtures/library-scopehoist/package.json +8 -0
  195. package/test/fixtures/local-plugin-config-pkg/.atlaspackrc +3 -0
  196. package/test/fixtures/local-plugin-config-pkg/node_modules/atlaspack-config-local/index.json +8 -0
  197. package/test/fixtures/local-plugin-config-pkg/node_modules/atlaspack-config-local/local-plugin.js +7 -0
  198. package/test/fixtures/local-plugin-config-pkg/node_modules/atlaspack-config-local/package.json +7 -0
  199. package/test/fixtures/main-format-mismatch/package.json +8 -0
  200. package/test/fixtures/main-global/package.json +8 -0
  201. package/test/fixtures/main-mjs/package.json +8 -0
  202. package/test/fixtures/module-a.js +1 -0
  203. package/test/fixtures/module-b.js +1 -0
  204. package/test/fixtures/plugins/local-plugin.js +7 -0
  205. package/test/fixtures/plugins/node_modules/atlaspack-transformer-bad-engines/index.js +7 -0
  206. package/test/fixtures/plugins/node_modules/atlaspack-transformer-bad-engines/package.json +7 -0
  207. package/test/fixtures/plugins/node_modules/atlaspack-transformer-no-engines/index.js +7 -0
  208. package/test/fixtures/plugins/node_modules/atlaspack-transformer-no-engines/package.json +4 -0
  209. package/test/fixtures/targets-default-distdir-none/package.json +5 -0
  210. package/test/fixtures/targets-default-distdir-one/package.json +8 -0
  211. package/test/fixtures/targets-default-distdir-two/package.json +18 -0
  212. package/test/requests/ConfigRequest.test.js +254 -0
  213. package/test/serializer.test.js +302 -0
  214. package/test/test-utils.js +80 -0
  215. package/test/utils.test.js +43 -0
@@ -0,0 +1,234 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = resolveOptions;
7
+ function _path() {
8
+ const data = _interopRequireDefault(require("path"));
9
+ _path = function () {
10
+ return data;
11
+ };
12
+ return data;
13
+ }
14
+ function _rust() {
15
+ const data = require("@atlaspack/rust");
16
+ _rust = function () {
17
+ return data;
18
+ };
19
+ return data;
20
+ }
21
+ function _fs() {
22
+ const data = require("@atlaspack/fs");
23
+ _fs = function () {
24
+ return data;
25
+ };
26
+ return data;
27
+ }
28
+ function _cache() {
29
+ const data = require("@atlaspack/cache");
30
+ _cache = function () {
31
+ return data;
32
+ };
33
+ return data;
34
+ }
35
+ function _packageManager() {
36
+ const data = require("@atlaspack/package-manager");
37
+ _packageManager = function () {
38
+ return data;
39
+ };
40
+ return data;
41
+ }
42
+ function _utils() {
43
+ const data = require("@atlaspack/utils");
44
+ _utils = function () {
45
+ return data;
46
+ };
47
+ return data;
48
+ }
49
+ var _loadDotEnv = _interopRequireDefault(require("./loadDotEnv"));
50
+ var _projectPath = require("./projectPath");
51
+ var _AtlaspackConfigRequest = require("./requests/AtlaspackConfigRequest");
52
+ function _featureFlags() {
53
+ const data = require("@atlaspack/feature-flags");
54
+ _featureFlags = function () {
55
+ return data;
56
+ };
57
+ return data;
58
+ }
59
+ var _constants = require("./constants");
60
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
61
+ // Default cache directory name
62
+ const DEFAULT_CACHE_DIRNAME = '.atlaspack-cache';
63
+ const LOCK_FILE_NAMES = ['yarn.lock', 'package-lock.json', 'pnpm-lock.yaml'];
64
+
65
+ // Generate a unique instanceId, will change on every run of atlaspack
66
+ function generateInstanceId(entries) {
67
+ return (0, _rust().hashString)(`${entries.join(',')}-${Date.now()}-${Math.round(Math.random() * 100)}`);
68
+ }
69
+
70
+ // Compiles an array of globs to regex - used for lazy include/excludes
71
+ function compileGlobs(globs) {
72
+ return globs.map(glob => (0, _utils().globToRegex)(glob));
73
+ }
74
+ async function resolveOptions(initialOptions) {
75
+ var _initialOptions$defau, _initialOptions$defau2, _initialOptions$defau3, _initialOptions$defau4, _initialOptions$addit, _initialOptions$defau5, _initialOptions$defau6, _initialOptions$defau7, _initialOptions$defau8, _initialOptions$defau9;
76
+ let inputFS = initialOptions.inputFS || new (_fs().NodeFS)();
77
+ let outputFS = initialOptions.outputFS || new (_fs().NodeFS)();
78
+ let inputCwd = inputFS.cwd();
79
+ let outputCwd = outputFS.cwd();
80
+ let entries;
81
+ if (initialOptions.entries == null || initialOptions.entries === '') {
82
+ entries = [];
83
+ } else if (Array.isArray(initialOptions.entries)) {
84
+ entries = initialOptions.entries.map(entry => _path().default.resolve(inputCwd, entry));
85
+ } else {
86
+ entries = [_path().default.resolve(inputCwd, initialOptions.entries)];
87
+ }
88
+ let shouldMakeEntryReferFolder = false;
89
+ if (entries.length === 1 && !(0, _utils().isGlob)(entries[0])) {
90
+ let [entry] = entries;
91
+ try {
92
+ shouldMakeEntryReferFolder = (await inputFS.stat(entry)).isDirectory();
93
+ } catch {
94
+ // ignore failing stat call
95
+ }
96
+ }
97
+
98
+ // getRootDir treats the input as files, so getRootDir(["/home/user/myproject"]) returns "/home/user".
99
+ // Instead we need to make the the entry refer to some file inside the specified folders if entries refers to the directory.
100
+ let entryRoot = (0, _utils().getRootDir)(shouldMakeEntryReferFolder ? [_path().default.join(entries[0], 'index')] : entries);
101
+ let projectRootFile = (await (0, _utils().resolveConfig)(inputFS, _path().default.join(entryRoot, 'index'), [...LOCK_FILE_NAMES, '.git', '.hg'], _path().default.parse(entryRoot).root)) || _path().default.join(inputCwd, 'index'); // ? Should this just be rootDir
102
+
103
+ let projectRoot = _path().default.dirname(projectRootFile);
104
+ let packageManager = initialOptions.packageManager || new (_packageManager().NodePackageManager)(inputFS, projectRoot);
105
+ let cacheDir =
106
+ // If a cacheDir is provided, resolve it relative to cwd. Otherwise,
107
+ // use a default directory resolved relative to the project root.
108
+ initialOptions.cacheDir != null ? _path().default.resolve(outputCwd, initialOptions.cacheDir) : _path().default.resolve(projectRoot, DEFAULT_CACHE_DIRNAME);
109
+
110
+ // Make the root watch directory configurable. This is useful in some cases
111
+ // where symlinked dependencies outside the project root need to trigger HMR
112
+ // updates. Default to the project root if not provided.
113
+ let watchDir = initialOptions.watchDir != null ? _path().default.resolve(initialOptions.watchDir) : projectRoot;
114
+ let cache = initialOptions.cache ?? (outputFS instanceof _fs().NodeFS ? new (_cache().LMDBCache)(cacheDir) : new (_cache().FSCache)(outputFS, cacheDir));
115
+ let mode = initialOptions.mode ?? 'development';
116
+ let shouldOptimize = (initialOptions === null || initialOptions === void 0 || (_initialOptions$defau = initialOptions.defaultTargetOptions) === null || _initialOptions$defau === void 0 ? void 0 : _initialOptions$defau.shouldOptimize) ?? mode === 'production';
117
+ let publicUrl = (initialOptions === null || initialOptions === void 0 || (_initialOptions$defau2 = initialOptions.defaultTargetOptions) === null || _initialOptions$defau2 === void 0 ? void 0 : _initialOptions$defau2.publicUrl) ?? '/';
118
+ let distDir = (initialOptions === null || initialOptions === void 0 || (_initialOptions$defau3 = initialOptions.defaultTargetOptions) === null || _initialOptions$defau3 === void 0 ? void 0 : _initialOptions$defau3.distDir) != null ? _path().default.resolve(inputCwd, initialOptions === null || initialOptions === void 0 || (_initialOptions$defau4 = initialOptions.defaultTargetOptions) === null || _initialOptions$defau4 === void 0 ? void 0 : _initialOptions$defau4.distDir) : undefined;
119
+ let shouldBuildLazily = initialOptions.shouldBuildLazily ?? false;
120
+ let lazyIncludes = compileGlobs(initialOptions.lazyIncludes ?? []);
121
+ if (lazyIncludes.length > 0 && !shouldBuildLazily) {
122
+ throw new Error('Lazy includes can only be provided when lazy building is enabled');
123
+ }
124
+ let lazyExcludes = compileGlobs(initialOptions.lazyExcludes ?? []);
125
+ if (lazyExcludes.length > 0 && !shouldBuildLazily) {
126
+ throw new Error('Lazy excludes can only be provided when lazy building is enabled');
127
+ }
128
+ let shouldContentHash = initialOptions.shouldContentHash ?? initialOptions.mode === 'production';
129
+ if (shouldBuildLazily && shouldContentHash) {
130
+ throw new Error('Lazy bundling does not work with content hashing');
131
+ }
132
+ let env = {
133
+ ...(await (0, _loadDotEnv.default)(initialOptions.env ?? {}, inputFS, _path().default.join(projectRoot, 'index'), projectRoot)),
134
+ ...process.env,
135
+ ...initialOptions.env
136
+ };
137
+ let port = determinePort(initialOptions.serveOptions, env.PORT);
138
+ return {
139
+ config: getRelativeConfigSpecifier(inputFS, projectRoot, initialOptions.config),
140
+ defaultConfig: getRelativeConfigSpecifier(inputFS, projectRoot, initialOptions.defaultConfig),
141
+ shouldPatchConsole: initialOptions.shouldPatchConsole ?? false,
142
+ env,
143
+ mode,
144
+ shouldAutoInstall: initialOptions.shouldAutoInstall ?? false,
145
+ hmrOptions: initialOptions.hmrOptions ?? null,
146
+ shouldBuildLazily,
147
+ lazyIncludes,
148
+ lazyExcludes,
149
+ unstableFileInvalidations: initialOptions.unstableFileInvalidations,
150
+ shouldBundleIncrementally: initialOptions.shouldBundleIncrementally ?? true,
151
+ shouldContentHash,
152
+ serveOptions: initialOptions.serveOptions ? {
153
+ ...initialOptions.serveOptions,
154
+ distDir: distDir ?? _path().default.join(outputCwd, 'dist'),
155
+ port
156
+ } : false,
157
+ shouldDisableCache: initialOptions.shouldDisableCache ?? false,
158
+ shouldProfile: initialOptions.shouldProfile ?? false,
159
+ shouldTrace: initialOptions.shouldTrace ?? false,
160
+ cacheDir,
161
+ watchDir,
162
+ watchBackend: initialOptions.watchBackend,
163
+ watchIgnore: initialOptions.watchIgnore,
164
+ entries: entries.map(e => (0, _projectPath.toProjectPath)(projectRoot, e)),
165
+ targets: initialOptions.targets,
166
+ logLevel: initialOptions.logLevel ?? 'info',
167
+ projectRoot,
168
+ inputFS,
169
+ outputFS,
170
+ cache,
171
+ packageManager,
172
+ additionalReporters: ((_initialOptions$addit = initialOptions.additionalReporters) === null || _initialOptions$addit === void 0 ? void 0 : _initialOptions$addit.map(({
173
+ packageName,
174
+ resolveFrom
175
+ }) => ({
176
+ packageName,
177
+ resolveFrom: (0, _projectPath.toProjectPath)(projectRoot, resolveFrom)
178
+ }))) ?? [],
179
+ instanceId: generateInstanceId(entries),
180
+ detailedReport: initialOptions.detailedReport,
181
+ defaultTargetOptions: {
182
+ shouldOptimize,
183
+ shouldScopeHoist: initialOptions === null || initialOptions === void 0 || (_initialOptions$defau5 = initialOptions.defaultTargetOptions) === null || _initialOptions$defau5 === void 0 ? void 0 : _initialOptions$defau5.shouldScopeHoist,
184
+ sourceMaps: (initialOptions === null || initialOptions === void 0 || (_initialOptions$defau6 = initialOptions.defaultTargetOptions) === null || _initialOptions$defau6 === void 0 ? void 0 : _initialOptions$defau6.sourceMaps) ?? true,
185
+ publicUrl,
186
+ ...(distDir != null ? {
187
+ distDir: (0, _projectPath.toProjectPath)(projectRoot, distDir)
188
+ } : {
189
+ /*::...null*/
190
+ }),
191
+ engines: initialOptions === null || initialOptions === void 0 || (_initialOptions$defau7 = initialOptions.defaultTargetOptions) === null || _initialOptions$defau7 === void 0 ? void 0 : _initialOptions$defau7.engines,
192
+ outputFormat: initialOptions === null || initialOptions === void 0 || (_initialOptions$defau8 = initialOptions.defaultTargetOptions) === null || _initialOptions$defau8 === void 0 ? void 0 : _initialOptions$defau8.outputFormat,
193
+ isLibrary: initialOptions === null || initialOptions === void 0 || (_initialOptions$defau9 = initialOptions.defaultTargetOptions) === null || _initialOptions$defau9 === void 0 ? void 0 : _initialOptions$defau9.isLibrary
194
+ },
195
+ featureFlags: {
196
+ ..._featureFlags().DEFAULT_FEATURE_FLAGS,
197
+ ...(initialOptions === null || initialOptions === void 0 ? void 0 : initialOptions.featureFlags)
198
+ },
199
+ atlaspackVersion: _constants.ATLASPACK_VERSION
200
+ };
201
+ }
202
+ function getRelativeConfigSpecifier(fs, projectRoot, specifier) {
203
+ if (specifier == null) {
204
+ return undefined;
205
+ } else if (_path().default.isAbsolute(specifier)) {
206
+ let resolveFrom = (0, _AtlaspackConfigRequest.getResolveFrom)(fs, projectRoot);
207
+ let relative = (0, _utils().relativePath)(_path().default.dirname(resolveFrom), specifier);
208
+ // If the config is outside the project root, use an absolute path so that if the project root
209
+ // moves the path still works. Otherwise, use a relative path so that the cache is portable.
210
+ return relative.startsWith('..') ? specifier : relative;
211
+ } else {
212
+ return specifier;
213
+ }
214
+ }
215
+ function determinePort(initialServerOptions, portInEnv, defaultPort = 1234) {
216
+ function parsePort(port) {
217
+ let parsedPort = Number(port);
218
+
219
+ // return undefined if port number defined in .env is not valid integer
220
+ if (!Number.isInteger(parsedPort)) {
221
+ return undefined;
222
+ }
223
+ return parsedPort;
224
+ }
225
+ if (!initialServerOptions) {
226
+ return typeof portInEnv !== 'undefined' ? parsePort(portInEnv) ?? defaultPort : defaultPort;
227
+ }
228
+
229
+ // 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.
230
+ if (initialServerOptions.port !== defaultPort) {
231
+ return initialServerOptions.port;
232
+ }
233
+ return typeof portInEnv !== 'undefined' ? parsePort(portInEnv) ?? defaultPort : defaultPort;
234
+ }
@@ -0,0 +1,216 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.cacheSerializedObject = cacheSerializedObject;
7
+ exports.deserialize = deserialize;
8
+ Object.defineProperty(exports, "deserializeRaw", {
9
+ enumerable: true,
10
+ get: function () {
11
+ return _serializerCore.deserializeRaw;
12
+ }
13
+ });
14
+ exports.deserializeToCache = deserializeToCache;
15
+ exports.prepareForSerialization = prepareForSerialization;
16
+ exports.registerSerializableClass = registerSerializableClass;
17
+ exports.removeSerializedObjectFromCache = removeSerializedObjectFromCache;
18
+ exports.restoreDeserializedObject = restoreDeserializedObject;
19
+ exports.serialize = serialize;
20
+ Object.defineProperty(exports, "serializeRaw", {
21
+ enumerable: true,
22
+ get: function () {
23
+ return _serializerCore.serializeRaw;
24
+ }
25
+ });
26
+ exports.unregisterSerializableClass = unregisterSerializableClass;
27
+ var _buildCache = require("./buildCache");
28
+ var _serializerCore = require("./serializerCore");
29
+ const nameToCtor = new Map();
30
+ const ctorToName = new Map();
31
+ function registerSerializableClass(name, ctor) {
32
+ if (ctorToName.has(ctor)) {
33
+ throw new Error('Class already registered with serializer');
34
+ }
35
+ nameToCtor.set(name, ctor);
36
+ ctorToName.set(ctor, name);
37
+ }
38
+ function unregisterSerializableClass(name, ctor) {
39
+ if (nameToCtor.get(name) === ctor) {
40
+ nameToCtor.delete(name);
41
+ }
42
+ if (ctorToName.get(ctor) === name) {
43
+ ctorToName.delete(ctor);
44
+ }
45
+ }
46
+ function shallowCopy(object) {
47
+ if (object && typeof object === 'object') {
48
+ if (Array.isArray(object)) {
49
+ return [...object];
50
+ }
51
+ if (object instanceof Map) {
52
+ return new Map(object);
53
+ }
54
+ if (object instanceof Set) {
55
+ return new Set(object);
56
+ }
57
+ return Object.create(Object.getPrototypeOf(object), Object.getOwnPropertyDescriptors(object));
58
+ }
59
+ return object;
60
+ }
61
+ function isBuffer(object) {
62
+ return object.buffer instanceof ArrayBuffer || typeof SharedArrayBuffer !== 'undefined' && object.buffer instanceof SharedArrayBuffer;
63
+ }
64
+ function shouldContinueMapping(value) {
65
+ return value && typeof value === 'object' && value.$$raw !== true;
66
+ }
67
+ function mapObject(object, fn, preOrder = false) {
68
+ let cache = new Map();
69
+ let memo = new Map();
70
+
71
+ // Memoize the passed function to ensure it always returns the exact same
72
+ // output by reference for the same input. This is important to maintain
73
+ // reference integrity when deserializing rather than cloning.
74
+ let memoizedFn = val => {
75
+ let res = memo.get(val);
76
+ if (res == null) {
77
+ res = fn(val);
78
+ memo.set(val, res);
79
+ }
80
+ return res;
81
+ };
82
+ let walk = (object, shouldCopy = false) => {
83
+ // Check the cache first, both for performance and cycle detection.
84
+ if (cache.has(object)) {
85
+ return cache.get(object);
86
+ }
87
+ let result = object;
88
+ cache.set(object, result);
89
+ let processKey = (key, value) => {
90
+ let newValue = value;
91
+ if (preOrder && value && typeof value === 'object') {
92
+ newValue = memoizedFn(value);
93
+ }
94
+
95
+ // Recursively walk the children
96
+ if (preOrder ? shouldContinueMapping(newValue) : newValue && typeof newValue === 'object' && shouldContinueMapping(object)) {
97
+ newValue = walk(newValue, newValue === value);
98
+ }
99
+ if (!preOrder && newValue && typeof newValue === 'object') {
100
+ newValue = memoizedFn(newValue);
101
+ }
102
+ if (newValue !== value) {
103
+ // Copy on write. We only need to do this when serializing, not deserializing.
104
+ if (object === result && preOrder && shouldCopy) {
105
+ result = shallowCopy(object);
106
+ cache.set(object, result);
107
+ }
108
+
109
+ // Replace the key with the new value
110
+ if (result instanceof Map) {
111
+ result.set(key, newValue);
112
+ } else if (result instanceof Set) {
113
+ let _result = result; // For Flow
114
+ // TODO: do we care about iteration order??
115
+ _result.delete(value);
116
+ _result.add(newValue);
117
+ } else {
118
+ result[key] = newValue;
119
+ }
120
+ }
121
+ };
122
+
123
+ // Iterate in various ways depending on type.
124
+ if (Array.isArray(object)) {
125
+ for (let i = 0; i < object.length; i++) {
126
+ processKey(i, object[i]);
127
+ }
128
+ } else if (object instanceof Map || object instanceof Set) {
129
+ for (let [key, val] of object.entries()) {
130
+ processKey(key, val);
131
+ }
132
+ } else if (!isBuffer(object)) {
133
+ for (let key in object) {
134
+ processKey(key, object[key]);
135
+ }
136
+ }
137
+ return result;
138
+ };
139
+ let mapped = memoizedFn(object);
140
+ if (preOrder ? shouldContinueMapping(mapped) : mapped && typeof mapped === 'object' && shouldContinueMapping(object)) {
141
+ return walk(mapped, mapped === object);
142
+ }
143
+ return mapped;
144
+ }
145
+ function prepareForSerialization(object) {
146
+ if (object !== null && object !== void 0 && object.$$raw) {
147
+ return object;
148
+ }
149
+ return mapObject(object, value => {
150
+ // Add a $$type property with the name of this class, if any is registered.
151
+ if (value && typeof value === 'object' && typeof value.constructor === 'function') {
152
+ let type = ctorToName.get(value.constructor);
153
+ if (type != null) {
154
+ let serialized = value;
155
+ let raw = false;
156
+ if (value && typeof value.serialize === 'function') {
157
+ // If the object has a serialize method, call it
158
+ serialized = value.serialize();
159
+ raw = (serialized && serialized.$$raw) ?? true;
160
+ if (serialized) {
161
+ delete serialized.$$raw;
162
+ }
163
+ }
164
+ return {
165
+ $$type: type,
166
+ $$raw: raw,
167
+ value: {
168
+ ...serialized
169
+ }
170
+ };
171
+ }
172
+ }
173
+ return value;
174
+ }, true);
175
+ }
176
+ function restoreDeserializedObject(object) {
177
+ return mapObject(object, value => {
178
+ // If the value has a $$type property, use it to restore the object type
179
+ if (value && value.$$type) {
180
+ let ctor = nameToCtor.get(value.$$type);
181
+ if (ctor == null) {
182
+ throw new Error(`Expected constructor ${value.$$type} to be registered with serializer to deserialize`);
183
+ }
184
+ if (typeof ctor.deserialize === 'function') {
185
+ return ctor.deserialize(value.value);
186
+ }
187
+ value = value.value;
188
+ Object.setPrototypeOf(value, ctor.prototype);
189
+ }
190
+ return value;
191
+ });
192
+ }
193
+ const serializeCache = (0, _buildCache.createBuildCache)();
194
+ function serialize(object) {
195
+ let cached = serializeCache.get(object);
196
+ if (cached) {
197
+ return cached;
198
+ }
199
+ let mapped = prepareForSerialization(object);
200
+ return (0, _serializerCore.serializeRaw)(mapped);
201
+ }
202
+ function deserialize(buffer) {
203
+ let obj = (0, _serializerCore.deserializeRaw)(buffer);
204
+ return restoreDeserializedObject(obj);
205
+ }
206
+ function cacheSerializedObject(object, buffer) {
207
+ serializeCache.set(object, buffer || serialize(object));
208
+ }
209
+ function deserializeToCache(buffer) {
210
+ let deserialized = deserialize(buffer);
211
+ serializeCache.set(deserialized, buffer);
212
+ return deserialized;
213
+ }
214
+ function removeSerializedObjectFromCache(object) {
215
+ serializeCache.delete(object);
216
+ }
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.serializeRaw = exports.deserializeRaw = void 0;
7
+ function _buffer() {
8
+ const data = require("buffer");
9
+ _buffer = function () {
10
+ return data;
11
+ };
12
+ return data;
13
+ }
14
+ function msgpackr() {
15
+ const data = _interopRequireWildcard(require("msgpackr"));
16
+ msgpackr = function () {
17
+ return data;
18
+ };
19
+ return data;
20
+ }
21
+ function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
22
+ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
23
+ let encoder = new (msgpackr().Encoder)({
24
+ structuredClone: true
25
+ });
26
+ let serializeRaw = v => _buffer().Buffer.from(encoder.encode(v));
27
+ exports.serializeRaw = serializeRaw;
28
+ let deserializeRaw = v => encoder.decode(v);
29
+ exports.deserializeRaw = deserializeRaw;
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.serializeRaw = exports.deserializeRaw = void 0;
7
+ function _v() {
8
+ const data = _interopRequireDefault(require("v8"));
9
+ _v = function () {
10
+ return data;
11
+ };
12
+ return data;
13
+ }
14
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
+ let serializeRaw = exports.serializeRaw = _v().default.serialize;
16
+ let deserializeRaw = exports.deserializeRaw = _v().default.deserialize;
@@ -0,0 +1,55 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = summarizeRequest;
7
+ function _path() {
8
+ const data = _interopRequireDefault(require("path"));
9
+ _path = function () {
10
+ return data;
11
+ };
12
+ return data;
13
+ }
14
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
+ const NODE_MODULES = `${_path().default.sep}node_modules${_path().default.sep}`;
16
+ const BUFFER_LIMIT = 5000000; // 5mb
17
+
18
+ async function summarizeRequest(fs, req) {
19
+ let {
20
+ content,
21
+ size
22
+ } = await summarizeDiskRequest(fs, req);
23
+ let isSource = isFilePathSource(fs, req.filePath);
24
+ return {
25
+ content,
26
+ size,
27
+ isSource
28
+ };
29
+ }
30
+ function isFilePathSource(fs, filePath) {
31
+ return !filePath.includes(NODE_MODULES);
32
+ }
33
+ async function summarizeDiskRequest(fs, req) {
34
+ let code = req.code;
35
+ let content;
36
+ let size;
37
+ if (code == null) {
38
+ // Get the filesize. If greater than BUFFER_LIMIT, use a stream to
39
+ // compute the hash. In the common case, it's faster to just read the entire
40
+ // file first and do the hash all at once without the overhead of streams.
41
+ size = (await fs.stat(req.filePath)).size;
42
+ if (size > BUFFER_LIMIT) {
43
+ content = fs.createReadStream(req.filePath);
44
+ } else {
45
+ content = await fs.readFile(req.filePath);
46
+ }
47
+ } else {
48
+ content = code;
49
+ size = Buffer.byteLength(code);
50
+ }
51
+ return {
52
+ content,
53
+ size
54
+ };
55
+ }
package/lib/types.js ADDED
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.SpecifierType = exports.Priority = exports.ExportsCondition = exports.BundleBehaviorNames = exports.BundleBehavior = void 0;
7
+ const SpecifierType = exports.SpecifierType = {
8
+ esm: 0,
9
+ commonjs: 1,
10
+ url: 2,
11
+ custom: 3
12
+ };
13
+ const Priority = exports.Priority = {
14
+ sync: 0,
15
+ parallel: 1,
16
+ lazy: 2
17
+ };
18
+
19
+ // Must match package_json.rs in node-resolver-rs.
20
+ const ExportsCondition = exports.ExportsCondition = {
21
+ import: 1 << 0,
22
+ require: 1 << 1,
23
+ module: 1 << 2,
24
+ style: 1 << 12,
25
+ sass: 1 << 13,
26
+ less: 1 << 14,
27
+ stylus: 1 << 15
28
+ };
29
+ const BundleBehavior = exports.BundleBehavior = {
30
+ inline: 0,
31
+ isolated: 1
32
+ };
33
+ const BundleBehaviorNames = exports.BundleBehaviorNames = Object.keys(BundleBehavior);
34
+
35
+ // Asset group nodes are essentially used as placeholders for the results of an asset request