@lwrjs/tools 0.19.0-alpha.0 → 0.19.0-alpha.10

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.
@@ -0,0 +1,59 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getProtoOf = Object.getPrototypeOf;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
7
+ var __markAsModule = (target) => __defProp(target, "__esModule", {value: true});
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, {get: all[name], enumerable: true});
11
+ };
12
+ var __exportStar = (target, module2, desc) => {
13
+ if (module2 && typeof module2 === "object" || typeof module2 === "function") {
14
+ for (let key of __getOwnPropNames(module2))
15
+ if (!__hasOwnProp.call(target, key) && key !== "default")
16
+ __defProp(target, key, {get: () => module2[key], enumerable: !(desc = __getOwnPropDesc(module2, key)) || desc.enumerable});
17
+ }
18
+ return target;
19
+ };
20
+ var __toModule = (module2) => {
21
+ return __exportStar(__markAsModule(__defProp(module2 != null ? __create(__getProtoOf(module2)) : {}, "default", module2 && module2.__esModule && "default" in module2 ? {get: () => module2.default, enumerable: true} : {value: module2, enumerable: true})), module2);
22
+ };
23
+
24
+ // packages/@lwrjs/tools/src/plugins/json-with.ts
25
+ __markAsModule(exports);
26
+ __export(exports, {
27
+ default: () => jsonWithPlugin
28
+ });
29
+ var import_fs_extra = __toModule(require("fs-extra"));
30
+ var import_path = __toModule(require("path"));
31
+ function jsonWithPlugin() {
32
+ return {
33
+ name: "json-with-loader",
34
+ setup(build) {
35
+ build.onLoad({filter: /.*/}, async (args) => {
36
+ if (args.with?.type === "json") {
37
+ try {
38
+ const contents = await import_fs_extra.default.readFile(args.path, "utf8");
39
+ const jsonData = JSON.parse(contents);
40
+ return {
41
+ contents: `module.exports = ${JSON.stringify(jsonData)}`,
42
+ loader: "js",
43
+ resolveDir: import_path.default.dirname(args.path)
44
+ };
45
+ } catch (error) {
46
+ return {
47
+ errors: [
48
+ {
49
+ text: `Failed to load JSON file with { type: 'json' }: ${error instanceof Error ? error.message : String(error)}`,
50
+ location: {file: args.path}
51
+ }
52
+ ]
53
+ };
54
+ }
55
+ }
56
+ });
57
+ }
58
+ };
59
+ }
@@ -37,6 +37,7 @@ var import_config = __toModule(require("@lwrjs/config"));
37
37
  var import_request_script = __toModule(require("./util/request-script.cjs"));
38
38
  var import_generate_entry_plugin = __toModule(require("./plugins/generate-entry-plugin.cjs"));
39
39
  var import_build_server_plugin = __toModule(require("./plugins/build-server-plugin.cjs"));
40
+ var import_json_with = __toModule(require("./plugins/json-with.cjs"));
40
41
  var REQUEST_SCRIPT_NAME = "index.js";
41
42
  async function build(buildOptions, config) {
42
43
  const {outputDir, normalizedOutputDir, minify} = buildOptions;
@@ -66,7 +67,7 @@ async function build(buildOptions, config) {
66
67
  banner: {
67
68
  js: createEnvVarHeader()
68
69
  },
69
- plugins: [(0, import_generate_entry_plugin.default)(), (0, import_build_server_plugin.default)(config, outputDir)],
70
+ plugins: [(0, import_generate_entry_plugin.default)(), (0, import_build_server_plugin.default)(config, outputDir), (0, import_json_with.default)()],
70
71
  outfile: import_path.default.join(normalizedOutputDir, "ssr.js")
71
72
  });
72
73
  await import_fs_extra.default.writeFile(import_path.default.join(normalizedOutputDir, REQUEST_SCRIPT_NAME), (0, import_request_script.getMainScriptContent)());
@@ -0,0 +1,3 @@
1
+ import type { Plugin } from 'esbuild';
2
+ export default function jsonWithPlugin(): Plugin;
3
+ //# sourceMappingURL=json-with.d.ts.map
@@ -0,0 +1,40 @@
1
+ // This plugin is a temporary solution to handle JSON imports with the 'with' syntax
2
+ // until esbuild adds native support for it. Once esbuild supports the 'with' syntax
3
+ // for JSON imports (https://github.com/evanw/esbuild/issues/3384), this plugin can be removed.
4
+ // The plugin allows us to use:
5
+ // import data from './data.json' with { type: 'json' };
6
+ // instead of the older assert syntax:
7
+ // import data from './data.json' assert { type: 'json' };
8
+ import fs from 'fs-extra';
9
+ import path from 'path';
10
+ export default function jsonWithPlugin() {
11
+ return {
12
+ name: 'json-with-loader',
13
+ setup(build) {
14
+ build.onLoad({ filter: /.*/ }, async (args) => {
15
+ if (args.with?.type === 'json') {
16
+ try {
17
+ const contents = await fs.readFile(args.path, 'utf8');
18
+ const jsonData = JSON.parse(contents);
19
+ return {
20
+ contents: `module.exports = ${JSON.stringify(jsonData)}`,
21
+ loader: 'js',
22
+ resolveDir: path.dirname(args.path),
23
+ };
24
+ }
25
+ catch (error) {
26
+ return {
27
+ errors: [
28
+ {
29
+ text: `Failed to load JSON file with { type: 'json' }: ${error instanceof Error ? error.message : String(error)}`,
30
+ location: { file: args.path },
31
+ },
32
+ ],
33
+ };
34
+ }
35
+ }
36
+ });
37
+ },
38
+ };
39
+ }
40
+ //# sourceMappingURL=json-with.js.map
@@ -8,6 +8,7 @@ import { LWR_VERSION, LWC_VERSION, PWA_KIT_RUNTIME_VERSION, MIN_LWR_VERSION, MIN
8
8
  import { getMainScriptContent } from './util/request-script.js';
9
9
  import generateLwrEntry from './plugins/generate-entry-plugin.js';
10
10
  import buildLwrServer from './plugins/build-server-plugin.js';
11
+ import jsonPlugin from './plugins/json-with.js';
11
12
  export const REQUEST_SCRIPT_NAME = 'index.js';
12
13
  async function build(buildOptions, config) {
13
14
  const { outputDir, normalizedOutputDir, minify } = buildOptions;
@@ -44,7 +45,7 @@ async function build(buildOptions, config) {
44
45
  banner: {
45
46
  js: createEnvVarHeader(),
46
47
  },
47
- plugins: [generateLwrEntry(), buildLwrServer(config, outputDir)],
48
+ plugins: [generateLwrEntry(), buildLwrServer(config, outputDir), jsonPlugin()],
48
49
  // MRT expects an entry point named `ssr.js`
49
50
  outfile: path.join(normalizedOutputDir, 'ssr.js'),
50
51
  });
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
7
- "version": "0.19.0-alpha.0",
7
+ "version": "0.19.0-alpha.10",
8
8
  "homepage": "https://developer.salesforce.com/docs/platform/lwr/overview",
9
9
  "repository": {
10
10
  "type": "git",
@@ -34,16 +34,16 @@
34
34
  "package.cjs"
35
35
  ],
36
36
  "dependencies": {
37
- "@lwrjs/config": "0.19.0-alpha.0",
38
- "@lwrjs/core": "0.19.0-alpha.0",
39
- "@lwrjs/diagnostics": "0.19.0-alpha.0",
40
- "@lwrjs/shared-utils": "0.19.0-alpha.0",
41
- "@lwrjs/static": "0.19.0-alpha.0",
42
- "esbuild": "^0.17.4",
37
+ "@lwrjs/config": "0.19.0-alpha.10",
38
+ "@lwrjs/core": "0.19.0-alpha.10",
39
+ "@lwrjs/diagnostics": "0.19.0-alpha.10",
40
+ "@lwrjs/shared-utils": "0.19.0-alpha.10",
41
+ "@lwrjs/static": "0.19.0-alpha.10",
42
+ "esbuild": "^0.25.2",
43
43
  "fs-extra": "^11.2.0"
44
44
  },
45
45
  "devDependencies": {
46
- "@lwrjs/types": "0.19.0-alpha.0",
46
+ "@lwrjs/types": "0.19.0-alpha.10",
47
47
  "jest": "29.7.0",
48
48
  "ts-jest": "^29.2.6"
49
49
  },
@@ -56,5 +56,5 @@
56
56
  "volta": {
57
57
  "extends": "../../../package.json"
58
58
  },
59
- "gitHead": "bf42316347f32c9ed0d1e30ae06b224ab61f8fc1"
59
+ "gitHead": "1c0d9cbabc81c0ded8080664debf86b9533bfc27"
60
60
  }