@jsenv/core 27.0.0-alpha.5 → 27.0.0-alpha.6

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jsenv/core",
3
- "version": "27.0.0-alpha.5",
3
+ "version": "27.0.0-alpha.6",
4
4
  "description": "Tool to develop, test and build js projects",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -11,8 +11,7 @@
11
11
  "node": ">=16.13.0"
12
12
  },
13
13
  "publishConfig": {
14
- "access": "public",
15
- "registry": "https://registry.npmjs.org"
14
+ "access": "public"
16
15
  },
17
16
  "type": "module",
18
17
  "imports": {},
@@ -107,4 +106,4 @@
107
106
  "redux": "4.1.2",
108
107
  "rollup": "2.70.1"
109
108
  }
110
- }
109
+ }
@@ -70,6 +70,8 @@ export const build = async ({
70
70
  writeOnFileSystem = true,
71
71
  buildDirectoryClean = true,
72
72
  baseUrl = "/",
73
+ assetManifest = true,
74
+ assetManifestFileRelativeUrl = "asset-manifest.json",
73
75
  }) => {
74
76
  const logger = createLogger({ logLevel })
75
77
  rootDirectoryUrl = assertAndNormalizeDirectoryUrl(rootDirectoryUrl)
@@ -84,7 +86,7 @@ export const build = async ({
84
86
  const entryPointKeys = Object.keys(entryPoints)
85
87
  if (entryPointKeys.length === 1) {
86
88
  logger.info(`
87
- build ${entryPointKeys[0]}`)
89
+ build "${entryPointKeys[0]}"`)
88
90
  } else {
89
91
  logger.info(`
90
92
  build ${entryPointKeys.length} entry points`)
@@ -119,22 +121,23 @@ build ${entryPointKeys.length} entry points`)
119
121
  scenario: "build",
120
122
  sourcemaps,
121
123
  })
122
- const loadEntryFiles = (cookEntryFile) => {
123
- Object.keys(entryPoints).forEach((key) => {
124
- cookEntryFile({
125
- trace: `"${key}" in entryPoints parameter`,
126
- type: "entry_point",
127
- specifier: key,
128
- })
129
- })
130
- }
124
+ const entryUrls = []
131
125
  try {
132
126
  await loadUrlGraph({
133
127
  urlGraph: rawGraph,
134
128
  kitchen: rawGraphKitchen,
135
129
  outDirectoryUrl: new URL(`.jsenv/build/`, rootDirectoryUrl),
136
130
  runtimeSupport,
137
- startLoading: loadEntryFiles,
131
+ startLoading: (cookEntryFile) => {
132
+ Object.keys(entryPoints).forEach((key) => {
133
+ const [, entryUrlInfo] = cookEntryFile({
134
+ trace: `"${key}" in entryPoints parameter`,
135
+ type: "entry_point",
136
+ specifier: key,
137
+ })
138
+ entryUrls.push(entryUrlInfo.url)
139
+ })
140
+ },
138
141
  })
139
142
  } catch (e) {
140
143
  prebuildTask.fail()
@@ -447,13 +450,23 @@ ${Object.keys(rawGraph.urlInfos).join("\n")}`,
447
450
  sourcemaps,
448
451
  })
449
452
  const buildTask = createTaskLog(logger, "build")
453
+ const postBuildEntryUrls = []
450
454
  try {
451
455
  await loadUrlGraph({
452
456
  urlGraph: finalGraph,
453
457
  kitchen: finalGraphKitchen,
454
458
  outDirectoryUrl: new URL(".jsenv/postbuild/", rootDirectoryUrl),
455
459
  runtimeSupport,
456
- startLoading: loadEntryFiles,
460
+ startLoading: (cookEntryFile) => {
461
+ entryUrls.forEach((entryUrl) => {
462
+ const [, postBuildEntryUrlInfo] = cookEntryFile({
463
+ trace: `entryPoint`,
464
+ type: "entry_point",
465
+ specifier: entryUrl,
466
+ })
467
+ postBuildEntryUrls.push(postBuildEntryUrlInfo.url)
468
+ })
469
+ },
457
470
  })
458
471
  } catch (e) {
459
472
  buildTask.fail()
@@ -540,12 +553,12 @@ ${Object.keys(finalGraph.urlInfos).join("\n")}`,
540
553
  {
541
554
  name: "jsenv:versioning",
542
555
  appliesDuring: { build: true },
543
- resolve: ({ parentUrl, specifier }) => {
544
- const buildUrl = buildUrls[specifier]
556
+ resolve: (reference) => {
557
+ const buildUrl = buildUrls[reference.specifier]
545
558
  if (buildUrl) {
546
559
  return buildUrl
547
560
  }
548
- const url = new URL(specifier, parentUrl).href
561
+ const url = new URL(reference.specifier, reference.parentUrl).href
549
562
  return url
550
563
  },
551
564
  formatReferencedUrl: (reference) => {
@@ -616,7 +629,15 @@ ${Object.keys(finalGraph.urlInfos).join("\n")}`,
616
629
  urlGraph: finalGraph,
617
630
  kitchen: versioningKitchen,
618
631
  runtimeSupport,
619
- startLoading: loadEntryFiles,
632
+ startLoading: (cookEntryFile) => {
633
+ postBuildEntryUrls.forEach((postBuildEntryUrl) => {
634
+ cookEntryFile({
635
+ trace: `entryPoint`,
636
+ type: "entry_point",
637
+ specifier: postBuildEntryUrl,
638
+ })
639
+ })
640
+ },
620
641
  })
621
642
  if (usedVersionMappings.length) {
622
643
  const versionMappingsNeeded = {}
@@ -689,6 +710,16 @@ ${Object.keys(finalGraph.urlInfos).join("\n")}`,
689
710
  )
690
711
  }),
691
712
  )
713
+ if (
714
+ versioning !== "none" &&
715
+ assetManifest &&
716
+ Object.keys(buildManifest).length
717
+ ) {
718
+ await writeFile(
719
+ new URL(assetManifestFileRelativeUrl, buildDirectoryUrl),
720
+ JSON.stringify(buildManifest, null, " "),
721
+ )
722
+ }
692
723
  }
693
724
  logger.info(createUrlGraphSummary(finalGraph, { title: "build files" }))
694
725
  return {
@@ -6,6 +6,12 @@ export const createBuilUrlsGenerator = ({ buildDirectoryUrl }) => {
6
6
  const cache = {}
7
7
  const generate = memoizeByUrl((url, urlInfo, parentUrlInfo) => {
8
8
  const directoryPath = determineDirectoryPath(urlInfo, parentUrlInfo)
9
+ let names = cache[directoryPath]
10
+ if (!names) {
11
+ names = []
12
+ cache[directoryPath] = names
13
+ }
14
+
9
15
  let name = urlToFilename(url)
10
16
  const { searchParams } = new URL(url)
11
17
  if (
@@ -15,12 +21,7 @@ export const createBuilUrlsGenerator = ({ buildDirectoryUrl }) => {
15
21
  ) {
16
22
  name = `${name}.js`
17
23
  }
18
- let names = cache[directoryPath]
19
- if (!names) {
20
- names = []
21
- cache[directoryPath] = names
22
- }
23
-
24
+ const [basename, extension] = splitFileExtension(name)
24
25
  let nameCandidate = name
25
26
  let integer = 1
26
27
  // eslint-disable-next-line no-constant-condition
@@ -30,7 +31,7 @@ export const createBuilUrlsGenerator = ({ buildDirectoryUrl }) => {
30
31
  break
31
32
  }
32
33
  integer++
33
- nameCandidate = `${name}${integer}`
34
+ nameCandidate = `${basename}${integer}${extension}`
34
35
  }
35
36
  return `${buildDirectoryUrl}${directoryPath}${nameCandidate}`
36
37
  })
@@ -40,6 +41,14 @@ export const createBuilUrlsGenerator = ({ buildDirectoryUrl }) => {
40
41
  }
41
42
  }
42
43
 
44
+ const splitFileExtension = (filename) => {
45
+ const dotLastIndex = filename.lastIndexOf(".")
46
+ if (dotLastIndex === -1) {
47
+ return [filename, ""]
48
+ }
49
+ return [filename.slice(0, dotLastIndex), filename.slice(dotLastIndex)]
50
+ }
51
+
43
52
  const determineDirectoryPath = (urlInfo, parentUrlInfo) => {
44
53
  if (urlInfo.isInline) {
45
54
  const parentDirectoryPath = determineDirectoryPath(parentUrlInfo)
@@ -52,6 +52,7 @@ export const loadUrlGraph = async ({
52
52
  reference: entryReference,
53
53
  urlInfo: entryUrlInfo,
54
54
  })
55
+ return [entryReference, entryUrlInfo]
55
56
  },
56
57
  )
57
58