@jsenv/core 39.5.25 → 39.6.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.
@@ -1,5 +1,5 @@
1
1
  import { parseSrcSet, stringifySrcSet } from "@jsenv/ast/src/html/html_src_set.js";
2
- import { urlHotMetas } from "./import_meta_hot.js";
2
+ import { urlHotMetas, dispatchBeforeFullReload, dispatchBeforePartialReload, dispatchAfterPartialReload, dispatchBeforePrune } from "./import_meta_hot.js";
3
3
 
4
4
  const initAutoreload = ({ mainFilePath }) => {
5
5
  const reloader = {
@@ -55,9 +55,11 @@ const initAutoreload = ({ mainFilePath }) => {
55
55
  (reloadMessage) => reloadMessage.type === "full",
56
56
  );
57
57
  if (someEffectIsFullReload) {
58
+ dispatchBeforeFullReload();
58
59
  reloadHtmlPage();
59
60
  return;
60
61
  }
62
+ dispatchBeforePartialReload();
61
63
  reloader.status.goTo("reloading");
62
64
  const onApplied = (reloadMessage) => {
63
65
  reloader.changes.remove(reloadMessage);
@@ -67,6 +69,7 @@ const initAutoreload = ({ mainFilePath }) => {
67
69
  () => {
68
70
  onApplied(reloadMessage);
69
71
  reloader.currentExecution = null;
72
+ dispatchAfterPartialReload();
70
73
  },
71
74
  (e) => {
72
75
  reloader.status.goTo("failed");
@@ -134,6 +137,7 @@ This could be due to syntax errors or importing non-existent modules (see errors
134
137
  // - import.meta.hot.accept() is not called (happens for HTML and CSS)
135
138
  if (type === "prune") {
136
139
  if (urlHotMeta) {
140
+ dispatchBeforePrune();
137
141
  delete urlHotMetas[urlToFetch];
138
142
  if (urlHotMeta.disposeCallback) {
139
143
  console.groupCollapsed(
@@ -5,12 +5,40 @@
5
5
 
6
6
  const urlHotMetas = {};
7
7
 
8
+ const createEvent = () => {
9
+ const callbackSet = new Set();
10
+ const addCallback = (callback) => {
11
+ callbackSet.add(callback);
12
+ return () => {
13
+ callbackSet.delete(callback);
14
+ };
15
+ };
16
+ const dispatch = () => {
17
+ for (const callback of callbackSet) {
18
+ callback();
19
+ }
20
+ };
21
+ return [{ addCallback }, dispatch];
22
+ };
23
+ const [beforePartialReload, dispatchBeforePartialReload] = createEvent();
24
+ const [afterPartialReload, dispatchAfterPartialReload] = createEvent();
25
+ const [beforeFullReload, dispatchBeforeFullReload] = createEvent();
26
+ const [beforePrune, dispatchBeforePrune] = createEvent();
27
+
28
+ const hotEvents = {
29
+ beforePartialReload,
30
+ afterPartialReload,
31
+ beforeFullReload,
32
+ beforePrune,
33
+ };
34
+
8
35
  const createImportMetaHot = (importMetaUrl) => {
9
36
  const data = {};
10
37
  const url = asUrlWithoutHotSearchParam(importMetaUrl);
11
38
 
12
39
  return {
13
40
  data,
41
+ events: hotEvents,
14
42
  accept: (firstArg, secondArg) => {
15
43
  if (!firstArg) {
16
44
  addUrlMeta(url, {
@@ -80,4 +108,4 @@ const asUrlWithoutHotSearchParam = (url) => {
80
108
  return url;
81
109
  };
82
110
 
83
- export { createImportMetaHot, urlHotMetas };
111
+ export { createImportMetaHot, dispatchAfterPartialReload, dispatchBeforeFullReload, dispatchBeforePartialReload, dispatchBeforePrune, urlHotMetas };
@@ -1809,14 +1809,20 @@ const urlIsInsideOf = (url, otherUrl) => {
1809
1809
 
1810
1810
  const urlToFileSystemPath = (url) => {
1811
1811
  const urlObject = new URL(url);
1812
- let urlString;
1813
- if (urlObject.hash) {
1814
- const origin =
1815
- urlObject.protocol === "file:" ? "file://" : urlObject.origin;
1816
- urlString = `${origin}${urlObject.pathname}${urlObject.search}%23${urlObject.hash.slice(1)}`;
1817
- } else {
1818
- urlString = urlObject.href;
1812
+ let { origin, pathname, hash } = urlObject;
1813
+ if (urlObject.protocol === "file:") {
1814
+ origin = "file://";
1815
+ }
1816
+ pathname = pathname
1817
+ .split("/")
1818
+ .map((part) => {
1819
+ return part.replace(/%(?![0-9A-F][0-9A-F])/g, "%25");
1820
+ })
1821
+ .join("/");
1822
+ if (hash) {
1823
+ pathname += `%23${encodeURIComponent(hash.slice(1))}`;
1819
1824
  }
1825
+ const urlString = `${origin}${pathname}`;
1820
1826
  const fileSystemPath = fileURLToPath(urlString);
1821
1827
  if (fileSystemPath[fileSystemPath.length - 1] === "/") {
1822
1828
  // remove trailing / so that nodejs path becomes predictable otherwise it logs
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jsenv/core",
3
- "version": "39.5.25",
3
+ "version": "39.6.0",
4
4
  "description": "Tool to develop, test and build js projects",
5
5
  "license": "MIT",
6
6
  "author": {
@@ -69,29 +69,29 @@
69
69
  "dependencies": {
70
70
  "@financial-times/polyfill-useragent-normaliser": "1.10.2",
71
71
  "@jsenv/abort": "4.3.0",
72
- "@jsenv/ast": "6.3.6",
73
- "@jsenv/filesystem": "4.10.12",
72
+ "@jsenv/ast": "6.3.7",
73
+ "@jsenv/filesystem": "4.10.13",
74
74
  "@jsenv/humanize": "1.2.8",
75
75
  "@jsenv/importmap": "1.2.1",
76
76
  "@jsenv/integrity": "0.0.2",
77
- "@jsenv/js-module-fallback": "1.3.50",
77
+ "@jsenv/js-module-fallback": "1.3.51",
78
78
  "@jsenv/node-esm-resolution": "1.0.6",
79
- "@jsenv/plugin-bundling": "2.7.17",
80
- "@jsenv/plugin-minification": "1.5.10",
81
- "@jsenv/plugin-supervisor": "1.5.29",
82
- "@jsenv/plugin-transpilation": "1.4.85",
79
+ "@jsenv/plugin-bundling": "2.7.19",
80
+ "@jsenv/plugin-minification": "1.5.11",
81
+ "@jsenv/plugin-supervisor": "1.5.30",
82
+ "@jsenv/plugin-transpilation": "1.4.86",
83
83
  "@jsenv/runtime-compat": "1.3.1",
84
84
  "@jsenv/server": "15.3.3",
85
- "@jsenv/sourcemap": "1.2.26",
85
+ "@jsenv/sourcemap": "1.2.27",
86
86
  "@jsenv/url-meta": "8.5.2",
87
- "@jsenv/urls": "2.5.3",
87
+ "@jsenv/urls": "2.5.4",
88
88
  "@jsenv/utils": "2.1.2",
89
89
  "string-width": "7.2.0"
90
90
  },
91
91
  "devDependencies": {
92
92
  "@babel/plugin-syntax-import-attributes": "7.26.0",
93
93
  "@babel/plugin-syntax-optional-chaining-assign": "7.25.9",
94
- "@eslint/compat": "1.2.2",
94
+ "@eslint/compat": "1.2.3",
95
95
  "@jsenv/assert": "workspace:*",
96
96
  "@jsenv/cli": "workspace:*",
97
97
  "@jsenv/core": "./",
@@ -104,13 +104,13 @@
104
104
  "@jsenv/snapshot": "workspace:*",
105
105
  "@jsenv/md-up": "workspace:*",
106
106
  "@jsenv/test": "workspace:*",
107
- "@playwright/browser-chromium": "1.48.2",
108
- "@playwright/browser-firefox": "1.48.2",
109
- "@playwright/browser-webkit": "1.48.2",
107
+ "@playwright/browser-chromium": "1.49.0",
108
+ "@playwright/browser-firefox": "1.49.0",
109
+ "@playwright/browser-webkit": "1.49.0",
110
110
  "babel-plugin-transform-async-to-promises": "0.8.18",
111
- "eslint": "9.14.0",
111
+ "eslint": "9.15.0",
112
112
  "open": "10.1.0",
113
- "playwright": "1.48.2",
113
+ "playwright": "1.49.0",
114
114
  "prettier": "3.3.3",
115
115
  "prettier-plugin-organize-imports": "4.1.0",
116
116
  "strip-ansi": "7.1.0"
@@ -2,7 +2,13 @@ import {
2
2
  parseSrcSet,
3
3
  stringifySrcSet,
4
4
  } from "@jsenv/ast/src/html/html_src_set.js";
5
- import { urlHotMetas } from "../../import_meta_hot/client/import_meta_hot.js";
5
+ import {
6
+ dispatchAfterPartialReload,
7
+ dispatchBeforeFullReload,
8
+ dispatchBeforePartialReload,
9
+ dispatchBeforePrune,
10
+ urlHotMetas,
11
+ } from "../../import_meta_hot/client/import_meta_hot.js";
6
12
 
7
13
  export const initAutoreload = ({ mainFilePath }) => {
8
14
  let debug = false;
@@ -62,9 +68,11 @@ export const initAutoreload = ({ mainFilePath }) => {
62
68
  (reloadMessage) => reloadMessage.type === "full",
63
69
  );
64
70
  if (someEffectIsFullReload) {
71
+ dispatchBeforeFullReload();
65
72
  reloadHtmlPage();
66
73
  return;
67
74
  }
75
+ dispatchBeforePartialReload();
68
76
  reloader.status.goTo("reloading");
69
77
  const onApplied = (reloadMessage) => {
70
78
  reloader.changes.remove(reloadMessage);
@@ -74,6 +82,7 @@ export const initAutoreload = ({ mainFilePath }) => {
74
82
  () => {
75
83
  onApplied(reloadMessage);
76
84
  reloader.currentExecution = null;
85
+ dispatchAfterPartialReload();
77
86
  },
78
87
  (e) => {
79
88
  reloader.status.goTo("failed");
@@ -141,6 +150,7 @@ This could be due to syntax errors or importing non-existent modules (see errors
141
150
  // - import.meta.hot.accept() is not called (happens for HTML and CSS)
142
151
  if (type === "prune") {
143
152
  if (urlHotMeta) {
153
+ dispatchBeforePrune();
144
154
  delete urlHotMetas[urlToFetch];
145
155
  if (urlHotMeta.disposeCallback) {
146
156
  console.groupCollapsed(
@@ -5,12 +5,46 @@
5
5
 
6
6
  export const urlHotMetas = {};
7
7
 
8
+ const createEvent = () => {
9
+ const callbackSet = new Set();
10
+ const addCallback = (callback) => {
11
+ callbackSet.add(callback);
12
+ return () => {
13
+ callbackSet.delete(callback);
14
+ };
15
+ };
16
+ const dispatch = () => {
17
+ for (const callback of callbackSet) {
18
+ callback();
19
+ }
20
+ };
21
+ return [{ addCallback }, dispatch];
22
+ };
23
+ const [beforePartialReload, dispatchBeforePartialReload] = createEvent();
24
+ const [afterPartialReload, dispatchAfterPartialReload] = createEvent();
25
+ const [beforeFullReload, dispatchBeforeFullReload] = createEvent();
26
+ const [beforePrune, dispatchBeforePrune] = createEvent();
27
+ export {
28
+ dispatchAfterPartialReload,
29
+ dispatchBeforeFullReload,
30
+ dispatchBeforePartialReload,
31
+ dispatchBeforePrune,
32
+ };
33
+
34
+ const hotEvents = {
35
+ beforePartialReload,
36
+ afterPartialReload,
37
+ beforeFullReload,
38
+ beforePrune,
39
+ };
40
+
8
41
  export const createImportMetaHot = (importMetaUrl) => {
9
42
  const data = {};
10
43
  const url = asUrlWithoutHotSearchParam(importMetaUrl);
11
44
 
12
45
  return {
13
46
  data,
47
+ events: hotEvents,
14
48
  accept: (firstArg, secondArg) => {
15
49
  if (!firstArg) {
16
50
  addUrlMeta(url, {