@ms-cloudpack/esm-stub-utilities 0.7.3 → 0.7.5
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/lib/createJSONStub.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Generates an ESM stub of a JSON file.
|
|
2
|
+
* Generates an ESM stub of a JSON file. This just inlines the file contents rather than running
|
|
3
|
+
* it in the sandbox.
|
|
3
4
|
* @param entryPath - The full path to the JSON entry file.
|
|
4
5
|
*/
|
|
5
6
|
export declare function createJSONStub(entryPath: string): Promise<string>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createJSONStub.d.ts","sourceRoot":"","sources":["../src/createJSONStub.ts"],"names":[],"mappings":"AAKA
|
|
1
|
+
{"version":3,"file":"createJSONStub.d.ts","sourceRoot":"","sources":["../src/createJSONStub.ts"],"names":[],"mappings":"AAKA;;;;GAIG;AACH,wBAAsB,cAAc,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CA0BvE"}
|
package/lib/createJSONStub.js
CHANGED
|
@@ -3,24 +3,20 @@ import path from 'path';
|
|
|
3
3
|
import { readJson } from '@ms-cloudpack/json-utilities';
|
|
4
4
|
import { isValidIdentifierName } from './isValidIdentifierName.js';
|
|
5
5
|
/**
|
|
6
|
-
* Generates an ESM stub of a JSON file.
|
|
6
|
+
* Generates an ESM stub of a JSON file. This just inlines the file contents rather than running
|
|
7
|
+
* it in the sandbox.
|
|
7
8
|
* @param entryPath - The full path to the JSON entry file.
|
|
8
9
|
*/
|
|
9
10
|
export async function createJSONStub(entryPath) {
|
|
10
11
|
if (path.extname(entryPath).toLowerCase() !== '.json') {
|
|
11
12
|
throw new Error('Not a JSON file: ' + entryPath);
|
|
12
13
|
}
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
if (!fs.existsSync(entryPath)) {
|
|
15
|
+
throw new Error('File does not exist: ' + entryPath);
|
|
16
|
+
}
|
|
16
17
|
const jsonData = await readJson(entryPath);
|
|
17
18
|
if (!jsonData) {
|
|
18
|
-
|
|
19
|
-
// so do an explicit existence check to give a better error message.
|
|
20
|
-
if (fs.existsSync(entryPath)) {
|
|
21
|
-
throw new Error('File is not valid JSON: ' + entryPath);
|
|
22
|
-
}
|
|
23
|
-
throw new Error('File does not exist: ' + entryPath);
|
|
19
|
+
throw new Error('File is not valid JSON: ' + entryPath);
|
|
24
20
|
}
|
|
25
21
|
const result = [`const data = ${JSON.stringify(jsonData, null, 2)};`, 'export default data;'];
|
|
26
22
|
if (jsonData && typeof jsonData === 'object' && !Array.isArray(jsonData)) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createJSONStub.js","sourceRoot":"","sources":["../src/createJSONStub.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,QAAQ,EAAE,MAAM,8BAA8B,CAAC;AACxD,OAAO,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AAEnE
|
|
1
|
+
{"version":3,"file":"createJSONStub.js","sourceRoot":"","sources":["../src/createJSONStub.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,QAAQ,EAAE,MAAM,8BAA8B,CAAC;AACxD,OAAO,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AAEnE;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,cAAc,CAAC,SAAiB;IACpD,IAAI,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,WAAW,EAAE,KAAK,OAAO,EAAE;QACrD,MAAM,IAAI,KAAK,CAAC,mBAAmB,GAAG,SAAS,CAAC,CAAC;KAClD;IAED,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,SAAS,CAAC,EAAE;QAC7B,MAAM,IAAI,KAAK,CAAC,uBAAuB,GAAG,SAAS,CAAC,CAAC;KACtD;IAED,MAAM,QAAQ,GAAG,MAAM,QAAQ,CAAC,SAAS,CAAC,CAAC;IAC3C,IAAI,CAAC,QAAQ,EAAE;QACb,MAAM,IAAI,KAAK,CAAC,0BAA0B,GAAG,SAAS,CAAC,CAAC;KACzD;IAED,MAAM,MAAM,GAAG,CAAC,gBAAgB,IAAI,CAAC,SAAS,CAAC,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC,GAAG,EAAE,sBAAsB,CAAC,CAAC;IAE9F,IAAI,QAAQ,IAAI,OAAO,QAAQ,KAAK,QAAQ,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE;QACxE,iEAAiE;QACjE,MAAM,CAAC,IAAI,CACT,GAAG,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC;aACrB,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,qBAAqB,CAAC,IAAI,CAAC,CAAC;aAC7C,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,gBAAgB,IAAI,WAAW,IAAI,GAAG,CAAC,CACzD,CAAC;KACH;IAED,OAAO,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAC3B,CAAC","sourcesContent":["import fs from 'fs';\nimport path from 'path';\nimport { readJson } from '@ms-cloudpack/json-utilities';\nimport { isValidIdentifierName } from './isValidIdentifierName.js';\n\n/**\n * Generates an ESM stub of a JSON file. This just inlines the file contents rather than running\n * it in the sandbox.\n * @param entryPath - The full path to the JSON entry file.\n */\nexport async function createJSONStub(entryPath: string): Promise<string> {\n if (path.extname(entryPath).toLowerCase() !== '.json') {\n throw new Error('Not a JSON file: ' + entryPath);\n }\n\n if (!fs.existsSync(entryPath)) {\n throw new Error('File does not exist: ' + entryPath);\n }\n\n const jsonData = await readJson(entryPath);\n if (!jsonData) {\n throw new Error('File is not valid JSON: ' + entryPath);\n }\n\n const result = [`const data = ${JSON.stringify(jsonData, null, 2)};`, 'export default data;'];\n\n if (jsonData && typeof jsonData === 'object' && !Array.isArray(jsonData)) {\n // Export individual properties if they're valid identifier names\n result.push(\n ...Object.keys(jsonData)\n .filter((name) => isValidIdentifierName(name))\n .map((prop) => `export const ${prop} = data.${prop};`),\n );\n }\n\n return result.join('\\n');\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ms-cloudpack/esm-stub-utilities",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.5",
|
|
4
4
|
"description": "Generates ESM stubs for CommonJS entry files.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
}
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@ms-cloudpack/json-utilities": "^0.0
|
|
17
|
+
"@ms-cloudpack/json-utilities": "^0.1.0",
|
|
18
18
|
"@ms-cloudpack/path-utilities": "^2.3.5",
|
|
19
19
|
"@ms-cloudpack/path-string-parsing": "^1.1.1",
|
|
20
20
|
"atob": "^2.1.2",
|