@jsenv/core 27.0.0-alpha.32 → 27.0.0-alpha.33

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.32",
3
+ "version": "27.0.0-alpha.33",
4
4
  "description": "Tool to develop, test and build js projects",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -46,19 +46,44 @@ import { injectGlobalVersionMapping } from "./inject_global_version_mappings.js"
46
46
  import { injectServiceWorkerUrls } from "./inject_service_worker_urls.js"
47
47
  import { resyncRessourceHints } from "./resync_ressource_hints.js"
48
48
 
49
+ /**
50
+ * Generate an optimized version of source files into a directory
51
+ * @param {Object} buildParameters
52
+ * @param {string|url} buildParameters.rootDirectoryUrl
53
+ * Directory containing source files
54
+ * @param {string|url} buildParameters.buildDirectoryUrl
55
+ * Directory where optimized files will be written
56
+ * @param {object} buildParameters.entryPoints
57
+ * Describe entry point paths and control their names in the build directory
58
+ * @param {object} buildParameters.runtimeCompat
59
+ * Code generated will be compatible with these runtimes
60
+ * @param {string="/"} buildParameters.baseUrl
61
+ * All urls in build file contents are prefixed with this url
62
+ * @param {boolean|object} [buildParameters.minification=true]
63
+ * Minify build file contents
64
+ * @param {boolean} [buildParameters.versioning=true]
65
+ * Controls if url in build file contents are versioned
66
+ * @param {('search_param'|'filename')} [buildParameters.versioningMethod="search_param"]
67
+ * Controls how url are versioned
68
+ * @param {boolean|string} [buildParameters.sourcemaps=false]
69
+ * Generate sourcemaps in the build directory
70
+ * @return {Object} buildReturnValue
71
+ * @return {Object} buildReturnValue.buildFileContents
72
+ * Contains all build file paths relative to the build directory and their content
73
+ * @return {Object} buildReturnValue.buildInlineContents
74
+ * Contains content that is inline into build files
75
+ * @return {Object} buildReturnValue.buildManifest
76
+ * Map build file paths without versioning to versioned file paths
77
+ */
49
78
  export const build = async ({
50
79
  signal = new AbortController().signal,
51
80
  logLevel = "info",
52
81
  rootDirectoryUrl,
53
82
  buildDirectoryUrl,
54
83
  entryPoints = {},
55
- // for now it's here but I think preview will become an other script
56
- // that will just pass different options to build project
57
- // and this function will be agnostic about "preview" concept
58
- isPreview = false,
59
84
 
60
85
  plugins = [],
61
- sourcemaps = isPreview ? "file" : false,
86
+ sourcemaps = false,
62
87
  nodeEsmResolution,
63
88
  fileSystemMagicResolution,
64
89
  injectedGlobals,
@@ -142,6 +167,7 @@ build ${entryPointKeys.length} entry points`)
142
167
  specifier: key,
143
168
  })
144
169
  entryUrls.push(entryUrlInfo.url)
170
+ entryUrlInfo.filename = entryPoints[key]
145
171
  })
146
172
  },
147
173
  })
@@ -4,6 +4,17 @@ import { memoizeByUrl } from "@jsenv/utils/memoize/memoize_by_url.js"
4
4
 
5
5
  export const createBuilUrlsGenerator = ({ buildDirectoryUrl }) => {
6
6
  const cache = {}
7
+
8
+ const getUrlName = (url, urlInfo) => {
9
+ if (!urlInfo) {
10
+ return urlToFilename(url)
11
+ }
12
+ if (urlInfo.filename) {
13
+ return urlInfo.filename
14
+ }
15
+ return urlToFilename(url)
16
+ }
17
+
7
18
  const generate = memoizeByUrl((url, { urlInfo, parentUrlInfo }) => {
8
19
  const directoryPath = determineDirectoryPath({
9
20
  urlInfo,
@@ -16,9 +27,7 @@ export const createBuilUrlsGenerator = ({ buildDirectoryUrl }) => {
16
27
  }
17
28
  const urlObject = new URL(url)
18
29
  let { search, hash } = urlObject
19
- let name = urlInfo
20
- ? urlInfo.filename || urlToFilename(url)
21
- : urlToFilename(url)
30
+ let name = getUrlName(url, urlInfo)
22
31
  const [basename, extension] = splitFileExtension(name)
23
32
  let nameCandidate = name
24
33
  let integer = 1
@@ -45,7 +45,7 @@ export const startBuildServer = async ({
45
45
  rootDirectoryUrl,
46
46
  buildDirectoryUrl,
47
47
  buildCommand,
48
- mainBuildFile,
48
+ mainBuildFile = "/index.html",
49
49
  watchedFilePatterns,
50
50
  cooldownBetweenFileEvents,
51
51
  autorestart,