@lwrjs/shared-utils 0.11.0-alpha.10 → 0.11.0-alpha.12
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/build/es/env.js +1 -1
- package/package.json +5 -17
- package/build/cjs/fs-watch.cjs +0 -43
- package/build/cjs/typescript.cjs +0 -81
- package/build/es/fs-watch.d.ts +0 -17
- package/build/es/fs-watch.js +0 -27
- package/build/es/typescript.d.ts +0 -7
- package/build/es/typescript.js +0 -70
package/build/es/env.js
CHANGED
|
@@ -39,7 +39,7 @@ export function getFeatureFlags() {
|
|
|
39
39
|
* Create a serializable context for the lwr/environment variable
|
|
40
40
|
*/
|
|
41
41
|
export function buildEnvironmentContext(runtimeParams) {
|
|
42
|
-
// The baseBath
|
|
42
|
+
// The baseBath from the config or set from the request (e.g. /shop)
|
|
43
43
|
const basePath = runtimeParams.basePath;
|
|
44
44
|
// The locale set from the request or the defaultLocale from the config (e.g. en-US)
|
|
45
45
|
const locale = runtimeParams.locale;
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
7
|
-
"version": "0.11.0-alpha.
|
|
7
|
+
"version": "0.11.0-alpha.12",
|
|
8
8
|
"homepage": "https://developer.salesforce.com/docs/platform/lwr/overview",
|
|
9
9
|
"repository": {
|
|
10
10
|
"type": "git",
|
|
@@ -26,14 +26,6 @@
|
|
|
26
26
|
"import": "./build/es/index.js",
|
|
27
27
|
"require": "./build/cjs/index.cjs"
|
|
28
28
|
},
|
|
29
|
-
"./fs-watch": {
|
|
30
|
-
"import": "./build/es/fs-watch.js",
|
|
31
|
-
"require": "./build/cjs/fs-watch.cjs"
|
|
32
|
-
},
|
|
33
|
-
"./typescript": {
|
|
34
|
-
"import": "./build/es/typescript.js",
|
|
35
|
-
"require": "./build/cjs/typescript.cjs"
|
|
36
|
-
},
|
|
37
29
|
"./compiler": {
|
|
38
30
|
"import": "./build/es/compiler.js",
|
|
39
31
|
"require": "./build/cjs/compiler.cjs"
|
|
@@ -45,7 +37,7 @@
|
|
|
45
37
|
"build/**/*.d.ts"
|
|
46
38
|
],
|
|
47
39
|
"dependencies": {
|
|
48
|
-
"@lwrjs/diagnostics": "0.11.0-alpha.
|
|
40
|
+
"@lwrjs/diagnostics": "0.11.0-alpha.12",
|
|
49
41
|
"es-module-lexer": "^1.3.0",
|
|
50
42
|
"fast-json-stable-stringify": "^2.1.0",
|
|
51
43
|
"magic-string": "^0.30.0",
|
|
@@ -54,20 +46,16 @@
|
|
|
54
46
|
"parse5-sax-parser": "^6.0.1",
|
|
55
47
|
"path-to-regexp": "^6.2.0",
|
|
56
48
|
"resolve": "^1.22.1",
|
|
49
|
+
"rollup": "^2.78.0",
|
|
57
50
|
"slugify": "^1.4.5"
|
|
58
51
|
},
|
|
59
|
-
"peerDependencies": {
|
|
60
|
-
"chokidar": "^3.5.3",
|
|
61
|
-
"esbuild": "^0.9.7",
|
|
62
|
-
"rollup": "^2.78.0"
|
|
63
|
-
},
|
|
64
52
|
"devDependencies": {
|
|
65
|
-
"@lwrjs/types": "0.11.0-alpha.
|
|
53
|
+
"@lwrjs/types": "0.11.0-alpha.12",
|
|
66
54
|
"@types/mime-types": "2.1.1",
|
|
67
55
|
"@types/path-to-regexp": "^1.7.0"
|
|
68
56
|
},
|
|
69
57
|
"engines": {
|
|
70
58
|
"node": ">=16.0.0"
|
|
71
59
|
},
|
|
72
|
-
"gitHead": "
|
|
60
|
+
"gitHead": "e19ffe5a48dc2b2b6d74d8acfa9658bedb5dd1ff"
|
|
73
61
|
}
|
package/build/cjs/fs-watch.cjs
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
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/shared-utils/src/fs-watch.ts
|
|
25
|
-
__markAsModule(exports);
|
|
26
|
-
__export(exports, {
|
|
27
|
-
WatcherFactoryImpl: () => WatcherFactoryImpl
|
|
28
|
-
});
|
|
29
|
-
var import_chokidar = __toModule(require("chokidar"));
|
|
30
|
-
var import_object = __toModule(require("./object.cjs"));
|
|
31
|
-
var import_diagnostics = __toModule(require("@lwrjs/diagnostics"));
|
|
32
|
-
var WatcherFactoryImpl = class {
|
|
33
|
-
createFileWatcher(options = {persistent: true, ignored: "**/node_modules/**"}) {
|
|
34
|
-
return import_chokidar.default.watch([], options);
|
|
35
|
-
}
|
|
36
|
-
setupWatcher(onModuleChange) {
|
|
37
|
-
const fileWatcher = this.createFileWatcher();
|
|
38
|
-
fileWatcher.on("change", (0, import_object.debounce)((file) => onModuleChange(file), 500));
|
|
39
|
-
fileWatcher.on("unlink", (0, import_object.debounce)((file) => onModuleChange(file), 500));
|
|
40
|
-
fileWatcher.on("add", (file) => import_diagnostics.logger.info(`Watching: ${file}`));
|
|
41
|
-
return fileWatcher;
|
|
42
|
-
}
|
|
43
|
-
};
|
package/build/cjs/typescript.cjs
DELETED
|
@@ -1,81 +0,0 @@
|
|
|
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/shared-utils/src/typescript.ts
|
|
25
|
-
__markAsModule(exports);
|
|
26
|
-
__export(exports, {
|
|
27
|
-
transpileTs: () => transpileTs
|
|
28
|
-
});
|
|
29
|
-
var import_fs = __toModule(require("fs"));
|
|
30
|
-
var import_path = __toModule(require("path"));
|
|
31
|
-
var import_esbuild = __toModule(require("esbuild"));
|
|
32
|
-
var esbuild = import_esbuild.default;
|
|
33
|
-
if (!import_esbuild.default) {
|
|
34
|
-
try {
|
|
35
|
-
esbuild = require("esbuild");
|
|
36
|
-
} catch {
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
var isCommonJs = typeof module !== "undefined";
|
|
40
|
-
var ESBUILD_EXTENSION_PLUGIN = function(absFilePath, format) {
|
|
41
|
-
return {
|
|
42
|
-
name: "replace-extension-plugin",
|
|
43
|
-
setup(build) {
|
|
44
|
-
build.onResolve({filter: /.*/}, ({path, importer, resolveDir}) => {
|
|
45
|
-
if (path !== absFilePath) {
|
|
46
|
-
if (path.startsWith(".")) {
|
|
47
|
-
const importeeExt = (0, import_path.extname)(path);
|
|
48
|
-
const ext = importeeExt !== "" ? importeeExt : ".ts";
|
|
49
|
-
let absPath = (0, import_path.join)((0, import_path.dirname)(importer), `${path}${ext}`);
|
|
50
|
-
if (!import_fs.default.existsSync(absPath) && ext === ".js") {
|
|
51
|
-
absPath = absPath.replace(".js", ".ts");
|
|
52
|
-
}
|
|
53
|
-
return {path: absPath};
|
|
54
|
-
} else {
|
|
55
|
-
return {
|
|
56
|
-
external: true
|
|
57
|
-
};
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
});
|
|
61
|
-
}
|
|
62
|
-
};
|
|
63
|
-
};
|
|
64
|
-
async function transpileTs(tsAbsPath, {rootDir, cacheDir}) {
|
|
65
|
-
const format = isCommonJs ? "cjs" : "esm";
|
|
66
|
-
const ext = format === "esm" ? ".mjs" : ".cjs";
|
|
67
|
-
const pathRelativeToRoot = tsAbsPath.replace(new RegExp(`^${rootDir}`), "");
|
|
68
|
-
const outBasename = pathRelativeToRoot.replace(/\//g, "_");
|
|
69
|
-
const outFilename = outBasename.replace(/\.ts$/, ext);
|
|
70
|
-
const outfile = (0, import_path.join)(cacheDir, outFilename);
|
|
71
|
-
await esbuild.build({
|
|
72
|
-
format,
|
|
73
|
-
bundle: true,
|
|
74
|
-
logLevel: "error",
|
|
75
|
-
entryPoints: [tsAbsPath],
|
|
76
|
-
sourcemap: true,
|
|
77
|
-
outfile,
|
|
78
|
-
plugins: [ESBUILD_EXTENSION_PLUGIN(tsAbsPath, format)]
|
|
79
|
-
});
|
|
80
|
-
return outfile;
|
|
81
|
-
}
|
package/build/es/fs-watch.d.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import type { Watcher, WatcherFactory, WatchOptions } from '@lwrjs/types';
|
|
2
|
-
/**
|
|
3
|
-
* Factory comptable with the LWR Runtime to create a file watch library for LWR dev server.
|
|
4
|
-
* When importing this module make sure the optional library 'chokidar' is installed.
|
|
5
|
-
*/
|
|
6
|
-
export declare class WatcherFactoryImpl implements WatcherFactory {
|
|
7
|
-
/**
|
|
8
|
-
* Set up a watcher with the given options
|
|
9
|
-
* @param options
|
|
10
|
-
*/
|
|
11
|
-
createFileWatcher(options?: WatchOptions): Watcher;
|
|
12
|
-
/**
|
|
13
|
-
* Set up file watcher
|
|
14
|
-
*/
|
|
15
|
-
setupWatcher(onModuleChange: Function): Watcher;
|
|
16
|
-
}
|
|
17
|
-
//# sourceMappingURL=fs-watch.d.ts.map
|
package/build/es/fs-watch.js
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import chokidar from 'chokidar';
|
|
2
|
-
import { debounce } from './object.js';
|
|
3
|
-
import { logger } from '@lwrjs/diagnostics';
|
|
4
|
-
/**
|
|
5
|
-
* Factory comptable with the LWR Runtime to create a file watch library for LWR dev server.
|
|
6
|
-
* When importing this module make sure the optional library 'chokidar' is installed.
|
|
7
|
-
*/
|
|
8
|
-
export class WatcherFactoryImpl {
|
|
9
|
-
/**
|
|
10
|
-
* Set up a watcher with the given options
|
|
11
|
-
* @param options
|
|
12
|
-
*/
|
|
13
|
-
createFileWatcher(options = { persistent: true, ignored: '**/node_modules/**' }) {
|
|
14
|
-
return chokidar.watch([], options);
|
|
15
|
-
}
|
|
16
|
-
/**
|
|
17
|
-
* Set up file watcher
|
|
18
|
-
*/
|
|
19
|
-
setupWatcher(onModuleChange) {
|
|
20
|
-
const fileWatcher = this.createFileWatcher();
|
|
21
|
-
fileWatcher.on('change', debounce((file) => onModuleChange(file), 500));
|
|
22
|
-
fileWatcher.on('unlink', debounce((file) => onModuleChange(file), 500));
|
|
23
|
-
fileWatcher.on('add', (file) => logger.info(`Watching: ${file}`));
|
|
24
|
-
return fileWatcher;
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
//# sourceMappingURL=fs-watch.js.map
|
package/build/es/typescript.d.ts
DELETED
package/build/es/typescript.js
DELETED
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
import fs from 'fs';
|
|
2
|
-
import { join, dirname, extname } from 'path';
|
|
3
|
-
import esbuildEsm from 'esbuild';
|
|
4
|
-
// https://github.com/evanw/esbuild/issues/706
|
|
5
|
-
// Fixed in 0.11.0 but upgrading past 0.9.7 has caused breaking changes for consumers...
|
|
6
|
-
// https://github.com/salesforce-experience-platform-emu/lwr/issues/1014
|
|
7
|
-
let esbuild = esbuildEsm;
|
|
8
|
-
if (!esbuildEsm) {
|
|
9
|
-
try {
|
|
10
|
-
esbuild = require('esbuild');
|
|
11
|
-
}
|
|
12
|
-
catch {
|
|
13
|
-
/* this is to support mjs/cjs dual impl */
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
// This is important as it checks which compilation to use esm or cjs based on the current way NodeJS is configured
|
|
17
|
-
const isCommonJs = typeof module !== 'undefined';
|
|
18
|
-
/* istanbul ignore next */
|
|
19
|
-
const ESBUILD_EXTENSION_PLUGIN = function (absFilePath, format) {
|
|
20
|
-
return {
|
|
21
|
-
name: 'replace-extension-plugin',
|
|
22
|
-
setup(build) {
|
|
23
|
-
build.onResolve({ filter: /.*/ }, ({ path, importer, resolveDir }) => {
|
|
24
|
-
if (path !== absFilePath) {
|
|
25
|
-
if (path.startsWith('.')) {
|
|
26
|
-
const importeeExt = extname(path);
|
|
27
|
-
const ext = importeeExt !== '' ? importeeExt : '.ts';
|
|
28
|
-
let absPath = join(dirname(importer), `${path}${ext}`);
|
|
29
|
-
// If typescript import is a ".js" try to find the equivalent .ts
|
|
30
|
-
// We do this to keep consistency with TS resolution
|
|
31
|
-
if (!fs.existsSync(absPath) && ext === '.js') {
|
|
32
|
-
absPath = absPath.replace('.js', '.ts');
|
|
33
|
-
}
|
|
34
|
-
return { path: absPath };
|
|
35
|
-
}
|
|
36
|
-
else {
|
|
37
|
-
return {
|
|
38
|
-
external: true,
|
|
39
|
-
};
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
});
|
|
43
|
-
},
|
|
44
|
-
};
|
|
45
|
-
};
|
|
46
|
-
// Transpile a typescript file and cache it
|
|
47
|
-
// The filename of the cached file is:
|
|
48
|
-
// - the path to the ts file relative to the project root
|
|
49
|
-
// - with all slashes replaced by underscores
|
|
50
|
-
// - and a new file extension of .mjs or .cjs
|
|
51
|
-
// eg: "/rootDir/path/to/file.ts" => "/cacheDir/path_to_file.*js"
|
|
52
|
-
export async function transpileTs(tsAbsPath, { rootDir, cacheDir }) {
|
|
53
|
-
const format = isCommonJs ? 'cjs' : 'esm';
|
|
54
|
-
const ext = format === 'esm' ? '.mjs' : '.cjs';
|
|
55
|
-
const pathRelativeToRoot = tsAbsPath.replace(new RegExp(`^${rootDir}`), '');
|
|
56
|
-
const outBasename = pathRelativeToRoot.replace(/\//g, '_'); // replace "/" with "_" in path
|
|
57
|
-
const outFilename = outBasename.replace(/\.ts$/, ext);
|
|
58
|
-
const outfile = join(cacheDir, outFilename);
|
|
59
|
-
await esbuild.build({
|
|
60
|
-
format,
|
|
61
|
-
bundle: true,
|
|
62
|
-
logLevel: 'error',
|
|
63
|
-
entryPoints: [tsAbsPath],
|
|
64
|
-
sourcemap: true,
|
|
65
|
-
outfile,
|
|
66
|
-
plugins: [ESBUILD_EXTENSION_PLUGIN(tsAbsPath, format)],
|
|
67
|
-
});
|
|
68
|
-
return outfile;
|
|
69
|
-
}
|
|
70
|
-
//# sourceMappingURL=typescript.js.map
|