@jsenv/core 31.0.1 → 31.1.1

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
@@ -17977,6 +17977,49 @@ const babelPluginMetadataImportMetaScenarios = () => {
17977
17977
  };
17978
17978
  };
17979
17979
 
17980
+ const replacePlaceholders = (urlInfo, replacements) => {
17981
+ const content = urlInfo.content;
17982
+ const magicSource = createMagicSource(content);
17983
+ Object.keys(replacements).forEach(key => {
17984
+ let index = content.indexOf(key);
17985
+ while (index !== -1) {
17986
+ const start = index;
17987
+ const end = index + key.length;
17988
+ magicSource.replace({
17989
+ start,
17990
+ end,
17991
+ replacement: urlInfo.type === "js_classic" || urlInfo.type === "js_module" || urlInfo.type === "html" ? JSON.stringify(replacements[key], null, " ") : replacements[key]
17992
+ });
17993
+ index = content.indexOf(key, end);
17994
+ }
17995
+ });
17996
+ return magicSource.toContentAndSourcemap();
17997
+ };
17998
+
17999
+ /*
18000
+ * Source code can contain the following
18001
+ * - __dev__
18002
+ * - __build__
18003
+ * A global will be injected with true/false when needed
18004
+ */
18005
+ const jsenvPluginGlobalScenarios = () => {
18006
+ const transformIfNeeded = (urlInfo, context) => {
18007
+ return replacePlaceholders(urlInfo, {
18008
+ false: context.dev,
18009
+ true: context.build
18010
+ });
18011
+ };
18012
+ return {
18013
+ name: "jsenv:global_scenario",
18014
+ appliesDuring: "*",
18015
+ transformUrlContent: {
18016
+ js_classic: transformIfNeeded,
18017
+ js_module: transformIfNeeded,
18018
+ html: transformIfNeeded
18019
+ }
18020
+ };
18021
+ };
18022
+
17980
18023
  const jsenvPluginCssTranspilation = () => {
17981
18024
  return {
17982
18025
  name: "jsenv:css_transpilation",
@@ -20309,7 +20352,7 @@ const getCorePlugins = ({
20309
20352
  runtimeCompat,
20310
20353
  clientMainFileUrl,
20311
20354
  urlResolution
20312
- }), jsenvPluginUrlVersion(), jsenvPluginCommonJsGlobals(), jsenvPluginImportMetaScenarios(), jsenvPluginNodeRuntime({
20355
+ }), jsenvPluginUrlVersion(), jsenvPluginCommonJsGlobals(), jsenvPluginImportMetaScenarios(), jsenvPluginGlobalScenarios(), jsenvPluginNodeRuntime({
20313
20356
  runtimeCompat
20314
20357
  }), jsenvPluginImportMetaHot(), ...(clientAutoreload ? [jsenvPluginAutoreload({
20315
20358
  ...clientAutoreload,
@@ -23975,7 +24018,7 @@ const descriptionFormatters = {
23975
24018
  }) => {
23976
24019
  return ANSI.color(`${UNICODE.FAILURE_RAW} execution ${index + 1} of ${total} timeout after ${executionParams.allocatedMs}ms`, EXECUTION_COLORS.timedout);
23977
24020
  },
23978
- efailedrrored: ({
24021
+ failed: ({
23979
24022
  index,
23980
24023
  total
23981
24024
  }) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jsenv/core",
3
- "version": "31.0.1",
3
+ "version": "31.1.1",
4
4
  "description": "Tool to develop, test and build js projects",
5
5
  "license": "MIT",
6
6
  "author": {
@@ -113,6 +113,6 @@
113
113
  "eslint-plugin-import": "2.27.5",
114
114
  "eslint-plugin-react": "7.32.2",
115
115
  "playwright": "1.31.2",
116
- "prettier": "2.8.4"
116
+ "prettier": "2.8.6"
117
117
  }
118
118
  }
@@ -0,0 +1,27 @@
1
+ /*
2
+ * Source code can contain the following
3
+ * - __dev__
4
+ * - __build__
5
+ * A global will be injected with true/false when needed
6
+ */
7
+
8
+ import { replacePlaceholders } from "@jsenv/plugin-placeholders"
9
+
10
+ export const jsenvPluginGlobalScenarios = () => {
11
+ const transformIfNeeded = (urlInfo, context) => {
12
+ return replacePlaceholders(urlInfo, {
13
+ __DEV__: context.dev,
14
+ __BUILD__: context.build,
15
+ })
16
+ }
17
+
18
+ return {
19
+ name: "jsenv:global_scenario",
20
+ appliesDuring: "*",
21
+ transformUrlContent: {
22
+ js_classic: transformIfNeeded,
23
+ js_module: transformIfNeeded,
24
+ html: transformIfNeeded,
25
+ },
26
+ }
27
+ }
@@ -8,6 +8,7 @@ import { jsenvPluginInline } from "./inline/jsenv_plugin_inline.js"
8
8
  import { jsenvPluginSupervisor } from "./supervisor/jsenv_plugin_supervisor.js"
9
9
  import { jsenvPluginCommonJsGlobals } from "./commonjs_globals/jsenv_plugin_commonjs_globals.js"
10
10
  import { jsenvPluginImportMetaScenarios } from "./import_meta_scenarios/jsenv_plugin_import_meta_scenarios.js"
11
+ import { jsenvPluginGlobalScenarios } from "./global_scenarios/jsenv_plugin_global_scenarios.js"
11
12
  import { jsenvPluginTranspilation } from "./transpilation/jsenv_plugin_transpilation.js"
12
13
  import { jsenvPluginNodeRuntime } from "./node_runtime/jsenv_plugin_node_runtime.js"
13
14
  // autoreload
@@ -89,6 +90,7 @@ export const getCorePlugins = ({
89
90
  jsenvPluginUrlVersion(),
90
91
  jsenvPluginCommonJsGlobals(),
91
92
  jsenvPluginImportMetaScenarios(),
93
+ jsenvPluginGlobalScenarios(),
92
94
 
93
95
  jsenvPluginNodeRuntime({ runtimeCompat }),
94
96
 
@@ -221,7 +221,7 @@ const descriptionFormatters = {
221
221
  EXECUTION_COLORS.timedout,
222
222
  )
223
223
  },
224
- efailedrrored: ({ index, total }) => {
224
+ failed: ({ index, total }) => {
225
225
  return ANSI.color(
226
226
  `${UNICODE.FAILURE_RAW} execution ${index + 1} of ${total} failed`,
227
227
  EXECUTION_COLORS.failed,