Skip to content

Commit 37ab75d

Browse files
authored
feat: update repo to esm
A big update as it has been some time since this repo has had any attention. Many of the fixes are the same as seen in the `vertigis-web-sdk` version of this update: vertigis/vertigis-web-sdk@b679778
1 parent 6a208f3 commit 37ab75d

32 files changed

+15506
-887
lines changed

.eslintrc.js renamed to .eslintrc.cjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const path = require("path");
22

33
module.exports = {
4-
extends: [path.join(__dirname, "config", ".eslintrc.js")],
4+
extends: [path.join(__dirname, "config", ".eslintrc")],
55
env: {
66
jest: true,
77
},

.npmrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
access=public
2-
package-lock=false
2+
engine-strict=true

.prettierignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
package-lock.json
2+
tsconfig.json.template

.prettierrc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
2-
"printWidth": 80,
2+
"arrowParens": "avoid",
3+
"printWidth": 120,
34
"tabWidth": 4,
45
"trailingComma": "es5"
56
}

.vscode/launch.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"skipFiles": ["<node_internals>/**"],
1313
"console": "integratedTerminal",
1414
"internalConsoleOptions": "neverOpen",
15-
"type": "pwa-node"
15+
"type": "node"
1616
},
1717
{
1818
"name": "Build 'test-lib' project",
@@ -21,7 +21,7 @@
2121
"runtimeExecutable": "npm",
2222
"skipFiles": ["<node_internals>/**"],
2323
"cwd": "${workspaceFolder}/test-lib",
24-
"type": "pwa-node"
24+
"type": "node"
2525
}
2626
]
2727
}

.vscode/settings.json

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"editor.formatOnSave": true,
3+
"editor.codeActionsOnSave": {
4+
"source.fixAll.eslint": "explicit"
5+
},
6+
"[javascript]": {
7+
"editor.formatOnSave": true
8+
},
9+
"[javascriptreact]": {
10+
"editor.formatOnSave": true
11+
},
12+
"[typescript]": {
13+
"editor.formatOnSave": true
14+
},
15+
"[typescriptreact]": {
16+
"editor.formatOnSave": true
17+
},
18+
"eslint.validate": ["javascript", "javascriptreact", "typescript", "typescriptreact"]
19+
}

babel.config.cjs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
module.exports = {
2+
presets: [
3+
[
4+
require("@babel/preset-env"),
5+
{
6+
targets: {
7+
node: "current",
8+
},
9+
},
10+
],
11+
require("@babel/preset-typescript"),
12+
],
13+
};

bin/vertigis-workflow-sdk.js

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
11
#!/usr/bin/env node
22
// @ts-check
3-
"use strict";
3+
// Necessary to turn this into a module, which allows top-level await.
4+
export {};
45

56
const args = process.argv.slice(2);
67

7-
const scriptIndex = args.findIndex(
8-
(x) => x === "build" || x === "create" || x === "generate" || x === "start"
9-
);
8+
const scriptIndex = args.findIndex(x => x === "build" || x === "create" || x === "generate" || x === "start");
109
const script = scriptIndex === -1 ? args[0] : args[scriptIndex];
1110

1211
if (["build", "create", "generate", "start"].includes(script)) {
13-
require(`../scripts/${script}`);
12+
try {
13+
await import(`../scripts/${script}.js`);
14+
} catch (e) {
15+
console.error(e);
16+
}
1417
} else {
15-
console.log('Unknown script "' + script + '".');
18+
console.error(`Unknown script '${script}'.`);
1619
}

config/.eslintrc/README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
This folder may seem bizarre but is necessary since existing SDK projects have
2+
their own eslint config that extends
3+
`require.resolve("@vertigis/web-sdk/config/.eslintrc")`. This will only work if
4+
`config/.eslintrc` is a Common JS module, but this project was converted to
5+
`"type": "module"`. It appears that Node will NOT resolve a module with a .cjs
6+
extension unless the extension is explicitly included in the path, which it
7+
isn't in this case.
8+
9+
By creating a folder with the same name containing a Common JS index.js and a
10+
package.json with `"type": "commonjs"`, it allows us to have this path still
11+
work via `require()` even after converting the SDK to ESM.

config/.eslintrc.js renamed to config/.eslintrc/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ module.exports = {
55
ecmaFeatures: {
66
jsx: true,
77
},
8-
ecmaVersion: 2018,
8+
ecmaVersion: 2021,
99
project: "./tsconfig.json",
1010
sourceType: "module",
1111
},
12-
plugins: ["@typescript-eslint", "react", "react-hooks"],
12+
plugins: ["@typescript-eslint", "only-warn", "react", "react-hooks"],
1313
env: {
1414
browser: true,
1515
commonjs: true,

0 commit comments

Comments
 (0)