@jsenv/core 30.3.9 → 30.4.0

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/dist/main.js CHANGED
@@ -7093,10 +7093,30 @@ const createUrlGraph = () => {
7093
7093
  if (!parentUrlInfo) {
7094
7094
  return null;
7095
7095
  }
7096
- const firstReferenceOnThatUrl = parentUrlInfo.references.find(reference => {
7097
- return urlSpecifierEncoding.decode(reference) === specifier;
7098
- });
7099
- return firstReferenceOnThatUrl;
7096
+ const seen = [];
7097
+ const search = urlInfo => {
7098
+ const firstReferenceFound = urlInfo.references.find(reference => {
7099
+ return urlSpecifierEncoding.decode(reference) === specifier;
7100
+ });
7101
+ if (firstReferenceFound) {
7102
+ return firstReferenceFound;
7103
+ }
7104
+ for (const dependencyUrl of parentUrlInfo.dependencies) {
7105
+ if (seen.includes(dependencyUrl)) {
7106
+ continue;
7107
+ }
7108
+ seen.push(dependencyUrl);
7109
+ const dependencyUrlInfo = getUrlInfo(dependencyUrl);
7110
+ if (dependencyUrlInfo.isInline) {
7111
+ const firstRef = search(dependencyUrlInfo);
7112
+ if (firstRef) {
7113
+ return firstRef;
7114
+ }
7115
+ }
7116
+ }
7117
+ return null;
7118
+ };
7119
+ return search(parentUrlInfo);
7100
7120
  };
7101
7121
  const findDependent = (urlInfo, visitor) => {
7102
7122
  const seen = [urlInfo.url];
@@ -8852,7 +8872,7 @@ ${ANSI.color(normalizedReturnValue, ANSI.YELLOW)}
8852
8872
  type,
8853
8873
  subtype,
8854
8874
  originalUrl,
8855
- originalContent,
8875
+ originalContent = content,
8856
8876
  sourcemap,
8857
8877
  filename,
8858
8878
  status = 200,
@@ -8875,7 +8895,15 @@ ${ANSI.color(normalizedReturnValue, ANSI.YELLOW)}
8875
8895
  urlInfo.subtype = subtype || reference.expectedSubtype || "";
8876
8896
  // during build urls info are reused and load returns originalUrl/originalContent
8877
8897
  urlInfo.originalUrl = originalUrl || urlInfo.originalUrl;
8878
- urlInfo.originalContent = originalContent === undefined ? content : originalContent;
8898
+ if (originalContent !== urlInfo.originalContent) {
8899
+ urlInfo.originalContentEtag = undefined; // set by "initTransformations"
8900
+ }
8901
+
8902
+ if (content !== urlInfo.content) {
8903
+ urlInfo.contentEtag = undefined; // set by "applyFinalTransformations"
8904
+ }
8905
+
8906
+ urlInfo.originalContent = originalContent;
8879
8907
  urlInfo.content = content;
8880
8908
  urlInfo.sourcemap = sourcemap;
8881
8909
  if (data) {
@@ -20017,17 +20045,20 @@ const jsenvPluginAutoreload = ({
20017
20045
  })];
20018
20046
  };
20019
20047
 
20020
- const jsenvPluginCacheControl = () => {
20048
+ const jsenvPluginCacheControl = ({
20049
+ versionedUrls = true,
20050
+ maxAge = SECONDS_IN_30_DAYS$1
20051
+ }) => {
20021
20052
  return {
20022
20053
  name: "jsenv:cache_control",
20023
20054
  appliesDuring: "dev",
20024
20055
  augmentResponse: ({
20025
20056
  reference
20026
20057
  }) => {
20027
- if (reference.searchParams.has("v") && !reference.searchParams.has("hmr")) {
20058
+ if (versionedUrls && reference.searchParams.has("v") && !reference.searchParams.has("hmr")) {
20028
20059
  return {
20029
20060
  headers: {
20030
- "cache-control": `private,max-age=${SECONDS_IN_30_DAYS$1},immutable`
20061
+ "cache-control": `private,max-age=${maxAge},immutable`
20031
20062
  }
20032
20063
  };
20033
20064
  }
@@ -20169,11 +20200,15 @@ const getCorePlugins = ({
20169
20200
  clientFileChangeCallbackList,
20170
20201
  clientFilesPruneCallbackList,
20171
20202
  explorer,
20203
+ cacheControl,
20172
20204
  ribbon = true
20173
20205
  } = {}) => {
20174
20206
  if (explorer === true) {
20175
20207
  explorer = {};
20176
20208
  }
20209
+ if (cacheControl === true) {
20210
+ cacheControl = {};
20211
+ }
20177
20212
  if (supervisor === true) {
20178
20213
  supervisor = {};
20179
20214
  }
@@ -20214,7 +20249,7 @@ const getCorePlugins = ({
20214
20249
  ...clientAutoreload,
20215
20250
  clientFileChangeCallbackList,
20216
20251
  clientFilesPruneCallbackList
20217
- })] : []), jsenvPluginCacheControl(), ...(explorer ? [jsenvPluginExplorer({
20252
+ })] : []), ...(cacheControl ? [jsenvPluginCacheControl(cacheControl)] : []), ...(explorer ? [jsenvPluginExplorer({
20218
20253
  ...explorer,
20219
20254
  clientMainFileUrl
20220
20255
  })] : []), ...(ribbon ? [jsenvPluginRibbon({
@@ -21392,7 +21427,7 @@ ${ANSI.color(buildUrl, ANSI.MAGENTA)}
21392
21427
  }
21393
21428
  if (preferWithoutVersioning(reference)) {
21394
21429
  // when versioning is dynamic no need to take into account
21395
- // happend for:
21430
+ // happens for:
21396
21431
  // - specifier mapped by window.__v__()
21397
21432
  // - specifier mapped by importmap
21398
21433
  return null;
@@ -21752,7 +21787,7 @@ ${ANSI.color(buildUrl, ANSI.MAGENTA)}
21752
21787
  return finalUrlInfo.subtype === "service_worker" && finalUrlInfo.isEntryPoint;
21753
21788
  });
21754
21789
  if (serviceWorkerEntryUrlInfos.length > 0) {
21755
- const serviceWorkerUrls = {};
21790
+ const serviceWorkerResources = {};
21756
21791
  GRAPH.forEach(finalGraph, urlInfo => {
21757
21792
  if (urlInfo.isInline || !urlInfo.shouldHandle) {
21758
21793
  return;
@@ -21765,26 +21800,27 @@ ${ANSI.color(buildUrl, ANSI.MAGENTA)}
21765
21800
  // so that service worker source still changes and navigator
21766
21801
  // detect there is a change
21767
21802
  const specifier = findKey(buildUrls, urlInfo.url);
21768
- serviceWorkerUrls[specifier] = {
21769
- versioned: false,
21803
+ serviceWorkerResources[specifier] = {
21770
21804
  version: versionMap.get(urlInfo.url)
21771
21805
  };
21772
21806
  return;
21773
21807
  }
21808
+ const specifier = findKey(buildUrls, urlInfo.url);
21774
21809
  const versionedUrl = versionedUrlMap.get(urlInfo.url);
21775
21810
  const versionedSpecifier = findKey(buildUrls, versionedUrl);
21776
- serviceWorkerUrls[versionedSpecifier] = {
21777
- versioned: true
21811
+ serviceWorkerResources[specifier] = {
21812
+ version: versionMap.get(urlInfo.url),
21813
+ versionedUrl: versionedSpecifier
21778
21814
  };
21779
21815
  });
21780
21816
  serviceWorkerEntryUrlInfos.forEach(serviceWorkerEntryUrlInfo => {
21781
21817
  const magicSource = createMagicSource(serviceWorkerEntryUrlInfo.content);
21782
- const urlsWithoutSelf = {
21783
- ...serviceWorkerUrls
21818
+ const serviceWorkerResourcesWithoutSwScriptItSelf = {
21819
+ ...serviceWorkerResources
21784
21820
  };
21785
21821
  const serviceWorkerSpecifier = findKey(buildUrls, serviceWorkerEntryUrlInfo.url);
21786
- delete urlsWithoutSelf[serviceWorkerSpecifier];
21787
- magicSource.prepend(`\nself.serviceWorkerUrls = ${JSON.stringify(urlsWithoutSelf, null, " ")};\n`);
21822
+ delete serviceWorkerResourcesWithoutSwScriptItSelf[serviceWorkerSpecifier];
21823
+ magicSource.prepend(`\nself.resourcesFromJsenvBuild = ${JSON.stringify(serviceWorkerResourcesWithoutSwScriptItSelf, null, " ")};\n`);
21788
21824
  const {
21789
21825
  content,
21790
21826
  sourcemap
@@ -22157,6 +22193,7 @@ const createFileService = ({
22157
22193
  clientMainFileUrl,
22158
22194
  cooldownBetweenFileEvents,
22159
22195
  explorer,
22196
+ cacheControl,
22160
22197
  ribbon,
22161
22198
  sourcemaps,
22162
22199
  sourcemapsSourcesProtocol,
@@ -22264,6 +22301,7 @@ const createFileService = ({
22264
22301
  clientFileChangeCallbackList,
22265
22302
  clientFilesPruneCallbackList,
22266
22303
  explorer,
22304
+ cacheControl,
22267
22305
  ribbon
22268
22306
  })],
22269
22307
  minification: false,
@@ -22293,18 +22331,25 @@ const createFileService = ({
22293
22331
  // when file is modified
22294
22332
  return false;
22295
22333
  }
22296
- if (!watch) {
22334
+ if (!watch && urlInfo.contentEtag) {
22335
+ // file is not watched, check the filesystem
22297
22336
  let fileContentAsBuffer;
22298
22337
  try {
22299
22338
  fileContentAsBuffer = readFileSync$1(new URL(urlInfo.url));
22300
22339
  } catch (e) {
22301
22340
  if (e.code === "ENOENT") {
22341
+ // we should consider calling urlGraph.deleteUrlInfo(urlInfo)
22342
+ urlInfo.originalContentEtag = undefined;
22343
+ urlInfo.contentEtag = undefined;
22302
22344
  return false;
22303
22345
  }
22304
22346
  return false;
22305
22347
  }
22306
22348
  const fileContentEtag = bufferToEtag$1(fileContentAsBuffer);
22307
22349
  if (fileContentEtag !== urlInfo.originalContentEtag) {
22350
+ // we should consider calling urlGraph.considerModified(urlInfo)
22351
+ urlInfo.originalContentEtag = undefined;
22352
+ urlInfo.contentEtag = undefined;
22308
22353
  return false;
22309
22354
  }
22310
22355
  }
@@ -22622,6 +22667,7 @@ const startDevServer = async ({
22622
22667
  transpilation,
22623
22668
  explorer = true,
22624
22669
  // see jsenv_plugin_explorer.js
22670
+ cacheControl = true,
22625
22671
  ribbon = true,
22626
22672
  // toolbar = false,
22627
22673
 
@@ -22760,6 +22806,7 @@ const startDevServer = async ({
22760
22806
  clientMainFileUrl,
22761
22807
  cooldownBetweenFileEvents,
22762
22808
  explorer,
22809
+ cacheControl,
22763
22810
  ribbon,
22764
22811
  sourcemaps,
22765
22812
  sourcemapsSourcesProtocol,
@@ -23394,6 +23441,17 @@ const getCoverageFromReport = async ({
23394
23441
  };
23395
23442
  const isV8Coverage = coverage => Boolean(coverage.result);
23396
23443
 
23444
+ /*
23445
+ * Export a function capable to run a file on a runtime.
23446
+ *
23447
+ * - Used internally by "executeTestPlan" part of the documented API
23448
+ * - Used internally by "execute" an advanced API not documented
23449
+ * - logs generated during file execution can be collected
23450
+ * - logs generated during file execution can be mirrored (re-logged to the console)
23451
+ * - File is given allocatedMs to complete
23452
+ * - Errors are collected
23453
+ * - File execution result is returned, it contains status/errors/namespace/consoleCalls
23454
+ */
23397
23455
  const run = async ({
23398
23456
  signal = new AbortController().signal,
23399
23457
  logger,
@@ -24244,6 +24302,7 @@ const executePlan = async (plan, {
24244
24302
  }
24245
24303
  const afterExecutionInfo = {
24246
24304
  ...beforeExecutionInfo,
24305
+ runtimeVersion: runtime.version,
24247
24306
  endMs: Date.now(),
24248
24307
  executionResult
24249
24308
  };
@@ -24636,8 +24695,8 @@ const createRuntimeFromPlaywright = ({
24636
24695
  stopSignal,
24637
24696
  keepRunning,
24638
24697
  onConsole,
24639
- executablePath,
24640
24698
  headful = keepRunning,
24699
+ playwrightLaunchOptions = {},
24641
24700
  ignoreHTTPSErrors = true
24642
24701
  }) => {
24643
24702
  const cleanupCallbackList = createCallbackListNotifiedOnce();
@@ -24653,11 +24712,14 @@ const createRuntimeFromPlaywright = ({
24653
24712
  signal,
24654
24713
  browserName,
24655
24714
  stopOnExit: true,
24656
- playwrightOptions: {
24657
- headless: !headful,
24658
- executablePath
24715
+ playwrightLaunchOptions: {
24716
+ ...playwrightLaunchOptions,
24717
+ headless: !headful
24659
24718
  }
24660
24719
  });
24720
+ if (browser._initializer.version) {
24721
+ runtime.version = browser._initializer.version;
24722
+ }
24661
24723
  const browserContext = await browser.newContext({
24662
24724
  ignoreHTTPSErrors
24663
24725
  });
@@ -24974,7 +25036,7 @@ const launchBrowserUsingPlaywright = async ({
24974
25036
  signal,
24975
25037
  browserName,
24976
25038
  stopOnExit,
24977
- playwrightOptions
25039
+ playwrightLaunchOptions
24978
25040
  }) => {
24979
25041
  const launchBrowserOperation = Abort.startOperation();
24980
25042
  launchBrowserOperation.addAbortSignal(signal);
@@ -24995,7 +25057,7 @@ const launchBrowserUsingPlaywright = async ({
24995
25057
  const browserClass = playwright[browserName];
24996
25058
  try {
24997
25059
  const browser = await browserClass.launch({
24998
- ...playwrightOptions,
25060
+ ...playwrightLaunchOptions,
24999
25061
  // let's handle them to close properly browser + remove listener
25000
25062
  // instead of relying on playwright to do so
25001
25063
  handleSIGINT: false,
@@ -25086,23 +25148,26 @@ const registerEvent = ({
25086
25148
 
25087
25149
  const chromium = createRuntimeFromPlaywright({
25088
25150
  browserName: "chromium",
25089
- browserVersion: "110.0.5481.38",
25090
- // to update, check https://github.com/microsoft/playwright/releases
25151
+ // browserVersion will be set by "browser._initializer.version"
25152
+ // see also https://github.com/microsoft/playwright/releases
25153
+ browserVersion: "unset",
25091
25154
  coveragePlaywrightAPIAvailable: true
25092
25155
  });
25093
25156
  const chromiumIsolatedTab = chromium.isolatedTab;
25094
25157
 
25095
25158
  const firefox = createRuntimeFromPlaywright({
25096
25159
  browserName: "firefox",
25097
- browserVersion: "108.0.2" // to update, check https://github.com/microsoft/playwright/releases
25160
+ // browserVersion will be set by "browser._initializer.version"
25161
+ // see also https://github.com/microsoft/playwright/releases
25162
+ browserVersion: "unset"
25098
25163
  });
25099
-
25100
25164
  const firefoxIsolatedTab = firefox.isolatedTab;
25101
25165
 
25102
25166
  const webkit = createRuntimeFromPlaywright({
25103
25167
  browserName: "webkit",
25104
- browserVersion: "16.4",
25105
- // to update, check https://github.com/microsoft/playwright/releases
25168
+ // browserVersion will be set by "browser._initializer.version"
25169
+ // see also https://github.com/microsoft/playwright/releases
25170
+ browserVersion: "unset",
25106
25171
  ignoreErrorHook: error => {
25107
25172
  // we catch error during execution but safari throw unhandled rejection
25108
25173
  // in a non-deterministic way.
@@ -26176,6 +26241,17 @@ const createBuildFilesService = ({
26176
26241
  };
26177
26242
  const SECONDS_IN_30_DAYS = 60 * 60 * 24 * 30;
26178
26243
 
26244
+ /*
26245
+ * Export a function capable to execute a file on a runtime (browser or node) and return how it goes.
26246
+ *
26247
+ * - can be useful to execute a file in a browser/node.js programmatically
26248
+ * - not documented
26249
+ * - the most importants parts:
26250
+ * - fileRelativeUrl: the file to execute inside rootDirectoryUrl
26251
+ * - runtime: an object with a "run" method.
26252
+ * The run method will start a browser/node process and execute file in it
26253
+ * - Most of the logic lives in "./run.js" used by executeTestPlan to run tests
26254
+ */
26179
26255
  const execute = async ({
26180
26256
  signal = new AbortController().signal,
26181
26257
  handleSIGINT = true,
@@ -26216,11 +26292,11 @@ const execute = async ({
26216
26292
  };
26217
26293
  if (runtime.type === "browser") {
26218
26294
  if (!devServerOrigin) {
26219
- throw new TypeError(`devServerOrigin is required when running tests on browser(s)`);
26295
+ throw new TypeError(`devServerOrigin is required to execute file on a browser`);
26220
26296
  }
26221
26297
  const devServerStarted = await pingServer(devServerOrigin);
26222
26298
  if (!devServerStarted) {
26223
- throw new Error(`dev server not started at ${devServerOrigin}. It is required to run tests`);
26299
+ throw new Error(`no server listening at ${devServerOrigin}. It is required to execute file`);
26224
26300
  }
26225
26301
  }
26226
26302
  let result = await run({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jsenv/core",
3
- "version": "30.3.9",
3
+ "version": "30.4.0",
4
4
  "description": "Tool to develop, test and build js projects",
5
5
  "license": "MIT",
6
6
  "author": {
@@ -44,8 +44,8 @@
44
44
  "dev": "node --conditions=development ./scripts/dev/dev.mjs",
45
45
  "test": "node --conditions=development ./scripts/test/test.mjs",
46
46
  "test:resource_hints": "npm run test -- --only-resource-hints",
47
- "test:workspace": "npm run test --workspaces --if-present -- --workspace",
48
47
  "build": "node --conditions=development ./scripts/build/build.mjs",
48
+ "workspace:test": "npm run test --workspaces --if-present -- --workspace",
49
49
  "workspace:versions": "node ./scripts/publish/workspace_versions.mjs",
50
50
  "workspace:publish": "node ./scripts/publish/workspace_publish.mjs",
51
51
  "performances": "node --expose-gc ./scripts/performance/generate_performance_report.mjs --log --once",
@@ -107,11 +107,11 @@
107
107
  "@jsenv/plugin-globals": "./packages/jsenv-plugin-globals/",
108
108
  "@jsenv/plugin-placeholders": "./packages/jsenv-plugin-placeholders/",
109
109
  "@jsenv/performance-impact": "4.1.0",
110
- "eslint": "8.32.0",
110
+ "eslint": "8.35.0",
111
111
  "eslint-plugin-html": "7.1.0",
112
112
  "eslint-plugin-import": "2.27.5",
113
- "eslint-plugin-react": "7.32.1",
114
- "playwright": "1.30.0",
115
- "prettier": "2.8.3"
113
+ "eslint-plugin-react": "7.32.2",
114
+ "playwright": "1.31.2",
115
+ "prettier": "2.8.4"
116
116
  }
117
117
  }
@@ -1042,7 +1042,7 @@ ${ANSI.color(buildUrl, ANSI.MAGENTA)}
1042
1042
  }
1043
1043
  if (preferWithoutVersioning(reference)) {
1044
1044
  // when versioning is dynamic no need to take into account
1045
- // happend for:
1045
+ // happens for:
1046
1046
  // - specifier mapped by window.__v__()
1047
1047
  // - specifier mapped by importmap
1048
1048
  return null
@@ -1477,7 +1477,7 @@ ${ANSI.color(buildUrl, ANSI.MAGENTA)}
1477
1477
  },
1478
1478
  )
1479
1479
  if (serviceWorkerEntryUrlInfos.length > 0) {
1480
- const serviceWorkerUrls = {}
1480
+ const serviceWorkerResources = {}
1481
1481
  GRAPH.forEach(finalGraph, (urlInfo) => {
1482
1482
  if (urlInfo.isInline || !urlInfo.shouldHandle) {
1483
1483
  return
@@ -1490,31 +1490,36 @@ ${ANSI.color(buildUrl, ANSI.MAGENTA)}
1490
1490
  // so that service worker source still changes and navigator
1491
1491
  // detect there is a change
1492
1492
  const specifier = findKey(buildUrls, urlInfo.url)
1493
- serviceWorkerUrls[specifier] = {
1494
- versioned: false,
1493
+ serviceWorkerResources[specifier] = {
1495
1494
  version: versionMap.get(urlInfo.url),
1496
1495
  }
1497
1496
  return
1498
1497
  }
1498
+ const specifier = findKey(buildUrls, urlInfo.url)
1499
1499
  const versionedUrl = versionedUrlMap.get(urlInfo.url)
1500
1500
  const versionedSpecifier = findKey(buildUrls, versionedUrl)
1501
- serviceWorkerUrls[versionedSpecifier] = { versioned: true }
1501
+ serviceWorkerResources[specifier] = {
1502
+ version: versionMap.get(urlInfo.url),
1503
+ versionedUrl: versionedSpecifier,
1504
+ }
1502
1505
  })
1503
1506
  serviceWorkerEntryUrlInfos.forEach((serviceWorkerEntryUrlInfo) => {
1504
1507
  const magicSource = createMagicSource(
1505
1508
  serviceWorkerEntryUrlInfo.content,
1506
1509
  )
1507
- const urlsWithoutSelf = {
1508
- ...serviceWorkerUrls,
1510
+ const serviceWorkerResourcesWithoutSwScriptItSelf = {
1511
+ ...serviceWorkerResources,
1509
1512
  }
1510
1513
  const serviceWorkerSpecifier = findKey(
1511
1514
  buildUrls,
1512
1515
  serviceWorkerEntryUrlInfo.url,
1513
1516
  )
1514
- delete urlsWithoutSelf[serviceWorkerSpecifier]
1517
+ delete serviceWorkerResourcesWithoutSwScriptItSelf[
1518
+ serviceWorkerSpecifier
1519
+ ]
1515
1520
  magicSource.prepend(
1516
- `\nself.serviceWorkerUrls = ${JSON.stringify(
1517
- urlsWithoutSelf,
1521
+ `\nself.resourcesFromJsenvBuild = ${JSON.stringify(
1522
+ serviceWorkerResourcesWithoutSwScriptItSelf,
1518
1523
  null,
1519
1524
  " ",
1520
1525
  )};\n`,
@@ -0,0 +1,3 @@
1
+ # build/
2
+
3
+ Code implementing jsenv build can be found here.
@@ -35,6 +35,7 @@ export const createFileService = ({
35
35
  clientMainFileUrl,
36
36
  cooldownBetweenFileEvents,
37
37
  explorer,
38
+ cacheControl,
38
39
  ribbon,
39
40
  sourcemaps,
40
41
  sourcemapsSourcesProtocol,
@@ -145,6 +146,7 @@ export const createFileService = ({
145
146
  clientFileChangeCallbackList,
146
147
  clientFilesPruneCallbackList,
147
148
  explorer,
149
+ cacheControl,
148
150
  ribbon,
149
151
  }),
150
152
  ],
@@ -173,18 +175,25 @@ export const createFileService = ({
173
175
  // when file is modified
174
176
  return false
175
177
  }
176
- if (!watch) {
178
+ if (!watch && urlInfo.contentEtag) {
179
+ // file is not watched, check the filesystem
177
180
  let fileContentAsBuffer
178
181
  try {
179
182
  fileContentAsBuffer = readFileSync(new URL(urlInfo.url))
180
183
  } catch (e) {
181
184
  if (e.code === "ENOENT") {
185
+ // we should consider calling urlGraph.deleteUrlInfo(urlInfo)
186
+ urlInfo.originalContentEtag = undefined
187
+ urlInfo.contentEtag = undefined
182
188
  return false
183
189
  }
184
190
  return false
185
191
  }
186
192
  const fileContentEtag = bufferToEtag(fileContentAsBuffer)
187
193
  if (fileContentEtag !== urlInfo.originalContentEtag) {
194
+ // we should consider calling urlGraph.considerModified(urlInfo)
195
+ urlInfo.originalContentEtag = undefined
196
+ urlInfo.contentEtag = undefined
188
197
  return false
189
198
  }
190
199
  }
@@ -0,0 +1,13 @@
1
+ # dev/
2
+
3
+ Code implementing jsenv dev server can be found here.
4
+
5
+ # Description
6
+
7
+ Jsenv dev server is a file server injecting code into HTML to autoreload when a file is saved.
8
+
9
+ It uses a plugin pattern allowing to control dev server behaviour
10
+
11
+ - Plugins can be used to transform file content before serving them; And many more things
12
+ - Some plugins are internal to jsenv and can be configured through parameters
13
+ - Some plugins are published in their own packages and can be passed via startDevServer "plugins" parameter
@@ -72,6 +72,7 @@ export const startDevServer = async ({
72
72
  fileSystemMagicRedirection,
73
73
  transpilation,
74
74
  explorer = true, // see jsenv_plugin_explorer.js
75
+ cacheControl = true,
75
76
  ribbon = true,
76
77
  // toolbar = false,
77
78
 
@@ -209,6 +210,7 @@ export const startDevServer = async ({
209
210
  clientMainFileUrl,
210
211
  cooldownBetweenFileEvents,
211
212
  explorer,
213
+ cacheControl,
212
214
  ribbon,
213
215
  sourcemaps,
214
216
  sourcemapsSourcesProtocol,
@@ -1,3 +1,15 @@
1
+ /*
2
+ * Export a function capable to execute a file on a runtime (browser or node) and return how it goes.
3
+ *
4
+ * - can be useful to execute a file in a browser/node.js programmatically
5
+ * - not documented
6
+ * - the most importants parts:
7
+ * - fileRelativeUrl: the file to execute inside rootDirectoryUrl
8
+ * - runtime: an object with a "run" method.
9
+ * The run method will start a browser/node process and execute file in it
10
+ * - Most of the logic lives in "./run.js" used by executeTestPlan to run tests
11
+ */
12
+
1
13
  import { Abort, raceProcessTeardownEvents } from "@jsenv/abort"
2
14
  import { assertAndNormalizeDirectoryUrl } from "@jsenv/filesystem"
3
15
  import { createLogger } from "@jsenv/log"
@@ -51,13 +63,13 @@ export const execute = async ({
51
63
  if (runtime.type === "browser") {
52
64
  if (!devServerOrigin) {
53
65
  throw new TypeError(
54
- `devServerOrigin is required when running tests on browser(s)`,
66
+ `devServerOrigin is required to execute file on a browser`,
55
67
  )
56
68
  }
57
69
  const devServerStarted = await pingServer(devServerOrigin)
58
70
  if (!devServerStarted) {
59
71
  throw new Error(
60
- `dev server not started at ${devServerOrigin}. It is required to run tests`,
72
+ `no server listening at ${devServerOrigin}. It is required to execute file`,
61
73
  )
62
74
  }
63
75
  }
@@ -1,3 +1,15 @@
1
+ /*
2
+ * Export a function capable to run a file on a runtime.
3
+ *
4
+ * - Used internally by "executeTestPlan" part of the documented API
5
+ * - Used internally by "execute" an advanced API not documented
6
+ * - logs generated during file execution can be collected
7
+ * - logs generated during file execution can be mirrored (re-logged to the console)
8
+ * - File is given allocatedMs to complete
9
+ * - Errors are collected
10
+ * - File execution result is returned, it contains status/errors/namespace/consoleCalls
11
+ */
12
+
1
13
  import { createId } from "@paralleldrive/cuid2"
2
14
  import { Abort, raceCallbacks } from "@jsenv/abort"
3
15
  import { ensureParentDirectories } from "@jsenv/filesystem"
@@ -2,7 +2,9 @@ import { createRuntimeFromPlaywright } from "./from_playwright.js"
2
2
 
3
3
  export const chromium = createRuntimeFromPlaywright({
4
4
  browserName: "chromium",
5
- browserVersion: "110.0.5481.38", // to update, check https://github.com/microsoft/playwright/releases
5
+ // browserVersion will be set by "browser._initializer.version"
6
+ // see also https://github.com/microsoft/playwright/releases
7
+ browserVersion: "unset",
6
8
  coveragePlaywrightAPIAvailable: true,
7
9
  })
8
10
  export const chromiumIsolatedTab = chromium.isolatedTab
@@ -2,6 +2,8 @@ import { createRuntimeFromPlaywright } from "./from_playwright.js"
2
2
 
3
3
  export const firefox = createRuntimeFromPlaywright({
4
4
  browserName: "firefox",
5
- browserVersion: "108.0.2", // to update, check https://github.com/microsoft/playwright/releases
5
+ // browserVersion will be set by "browser._initializer.version"
6
+ // see also https://github.com/microsoft/playwright/releases
7
+ browserVersion: "unset",
6
8
  })
7
9
  export const firefoxIsolatedTab = firefox.isolatedTab
@@ -46,8 +46,8 @@ export const createRuntimeFromPlaywright = ({
46
46
  keepRunning,
47
47
  onConsole,
48
48
 
49
- executablePath,
50
49
  headful = keepRunning,
50
+ playwrightLaunchOptions = {},
51
51
  ignoreHTTPSErrors = true,
52
52
  }) => {
53
53
  const cleanupCallbackList = createCallbackListNotifiedOnce()
@@ -62,11 +62,14 @@ export const createRuntimeFromPlaywright = ({
62
62
  signal,
63
63
  browserName,
64
64
  stopOnExit: true,
65
- playwrightOptions: {
65
+ playwrightLaunchOptions: {
66
+ ...playwrightLaunchOptions,
66
67
  headless: !headful,
67
- executablePath,
68
68
  },
69
69
  })
70
+ if (browser._initializer.version) {
71
+ runtime.version = browser._initializer.version
72
+ }
70
73
  const browserContext = await browser.newContext({ ignoreHTTPSErrors })
71
74
  return { browser, browserContext }
72
75
  })()
@@ -409,7 +412,7 @@ const launchBrowserUsingPlaywright = async ({
409
412
  signal,
410
413
  browserName,
411
414
  stopOnExit,
412
- playwrightOptions,
415
+ playwrightLaunchOptions,
413
416
  }) => {
414
417
  const launchBrowserOperation = Abort.startOperation()
415
418
  launchBrowserOperation.addAbortSignal(signal)
@@ -431,7 +434,7 @@ const launchBrowserUsingPlaywright = async ({
431
434
  const browserClass = playwright[browserName]
432
435
  try {
433
436
  const browser = await browserClass.launch({
434
- ...playwrightOptions,
437
+ ...playwrightLaunchOptions,
435
438
  // let's handle them to close properly browser + remove listener
436
439
  // instead of relying on playwright to do so
437
440
  handleSIGINT: false,
@@ -2,7 +2,9 @@ import { createRuntimeFromPlaywright } from "./from_playwright.js"
2
2
 
3
3
  export const webkit = createRuntimeFromPlaywright({
4
4
  browserName: "webkit",
5
- browserVersion: "16.4", // to update, check https://github.com/microsoft/playwright/releases
5
+ // browserVersion will be set by "browser._initializer.version"
6
+ // see also https://github.com/microsoft/playwright/releases
7
+ browserVersion: "unset",
6
8
  ignoreErrorHook: (error) => {
7
9
  // we catch error during execution but safari throw unhandled rejection
8
10
  // in a non-deterministic way.