Skip to content

Open source website builder and Webflow alternative. Webstudio is an advanced visual builder that connects to any headless CMS, supports all CSS properties, and can be hosted anywhere, including with us.

Migrate packages to native ESM (#493)

Bogdan Chadkinad04473f2644
diff --git a/apps/designer/.storybook/main.js b/apps/designer/.storybook/main.js
index 4991efd789..4f7ffdf951 100644
--- a/apps/designer/.storybook/main.js
+++ b/apps/designer/.storybook/main.js
@@ -22,6 +22,11 @@ module.exports = {
framework: "@storybook/react",
webpackFinal: async (config) => {
config.resolve.alias["~"] = path.resolve(__dirname, "../app");
+ // fix packages modules withoot extensions
+ for (const rule of config.module.rules) {
+ rule.resolve = rule.resolve || {};
+ rule.resolve.fullySpecified = false;
+ }
return config;
},
features: {
diff --git a/apps/designer/package.json b/apps/designer/package.json
index f3899cee71..26c0c75e8c 100644
--- a/apps/designer/package.json
+++ b/apps/designer/package.json
@@ -8,7 +8,7 @@
"start": "remix-serve build",
"typecheck": "tsc -b",
"lint": "eslint . --ext .ts,.tsx --max-warnings 0",
- "test": "jest",
+ "test": "NODE_OPTIONS=--experimental-vm-modules jest",
"checks": "yarn lint && yarn typecheck && yarn prettier --check && yarn test",
"watch:sdk": "relative-deps && relative-deps watch",
"prettier": "prettier \"*.{js,md,json,ts}\" \"{docs,app}/**/*.{js,md,json,ts}\"",
diff --git a/packages/asset-uploader/jest.config.js b/packages/asset-uploader/jest.config.js
index 4eeecbaf4e..e7fc137533 100644
--- a/packages/asset-uploader/jest.config.js
+++ b/packages/asset-uploader/jest.config.js
@@ -1 +1 @@
-module.exports = require("@webstudio-is/jest-config");
+export { default } from "@webstudio-is/jest-config";
diff --git a/packages/asset-uploader/package.json b/packages/asset-uploader/package.json
index 9f33c3f881..1b4fe58de9 100644
--- a/packages/asset-uploader/package.json
+++ b/packages/asset-uploader/package.json
@@ -4,9 +4,10 @@
"description": "Webstudio Asset Uploader",
"author": "Webstudio <[email protected]>",
"homepage": "https://webstudio.is",
+ "type": "module",
"scripts": {
"typecheck": "tsc --noEmit",
- "test": "jest",
+ "test": "NODE_OPTIONS=--experimental-vm-modules jest",
"checks": "yarn typecheck && yarn lint && yarn test",
"dev": "tsup --watch",
"build": "rm -fr lib tsconfig.tsbuildinfo && tsc",
@@ -29,7 +30,10 @@
"typescript": "4.7.4",
"zod": "^3.17.3"
},
- "main": "lib/index.js",
+ "exports": {
+ ".": "./lib/index.js",
+ "./server": "./server.js"
+ },
"types": "lib/index.d.ts",
"files": [
"lib/*",
@@ -44,7 +48,7 @@
"src/index.ts",
"src/index.server.ts"
],
- "format": "cjs",
+ "format": "esm",
"outDir": "lib"
}
}
diff --git a/packages/asset-uploader/server.js b/packages/asset-uploader/server.js
index 928878beec..a6fbe7c12c 100644
--- a/packages/asset-uploader/server.js
+++ b/packages/asset-uploader/server.js
@@ -1 +1 @@
-module.exports = require("./lib/index.server");
+export * from "./lib/index.server";
diff --git a/packages/asset-uploader/src/utils/get-asset-path.test.ts b/packages/asset-uploader/src/utils/get-asset-path.test.ts
index b69c311de4..b8294191f1 100644
--- a/packages/asset-uploader/src/utils/get-asset-path.test.ts
+++ b/packages/asset-uploader/src/utils/get-asset-path.test.ts
@@ -1,4 +1,4 @@
-/* eslint-disable @typescript-eslint/no-var-requires */
+import { jest } from "@jest/globals";
import { Asset, Location } from "@webstudio-is/prisma-client";
const commonAsset: Asset = {
@@ -31,8 +31,8 @@ describe("getAssetPath", () => {
});
describe("local", () => {
- test("returns local path with no custom path", () => {
- const { getAssetPath } = require("./get-asset-path");
+ test("returns local path with no custom path", async () => {
+ const { getAssetPath } = await import("./get-asset-path");
expect(
getAssetPath({
...commonAsset,
@@ -42,9 +42,9 @@ describe("getAssetPath", () => {
).toBe("/s/uploads/test.png");
});
- test("return local path with custom path", () => {
+ test("return local path with custom path", async () => {
process.env.FILE_UPLOAD_PATH = "assets";
- const { getAssetPath } = require("./get-asset-path");
+ const { getAssetPath } = await import("./get-asset-path");
expect(
getAssetPath({
...commonAsset,
@@ -55,11 +55,11 @@ describe("getAssetPath", () => {
});
});
describe("s3", () => {
- test("returns s3 url", () => {
+ test("returns s3 url", async () => {
process.env.S3_ENDPOINT = "https://fr1.s3.com";
process.env.S3_BUCKET = "bucket";
process.env.S3_REGION = "fr1";
- const { getAssetPath } = require("./get-asset-path");
+ const { getAssetPath } = await import("./get-asset-path");
expect(
getAssetPath({
...commonAsset,
@@ -68,11 +68,11 @@ describe("getAssetPath", () => {
})
).toBe("https://bucket.fr1.s3.com/test.png");
});
- test("returns s3 url and fixes extra slashes", () => {
+ test("returns s3 url and fixes extra slashes", async () => {
process.env.S3_ENDPOINT = "https://fr1.s3.com//";
process.env.S3_BUCKET = "bucket";
process.env.S3_REGION = "fr1";
- const { getAssetPath } = require("./get-asset-path");
+ const { getAssetPath } = await import("./get-asset-path");
expect(
getAssetPath({
...commonAsset,
@@ -83,12 +83,12 @@ describe("getAssetPath", () => {
});
});
describe("R2", () => {
- test("returns r2 url", () => {
+ test("returns r2 url", async () => {
process.env.S3_ENDPOINT = "https://userid.r2.cloudflarestorage.com";
process.env.S3_BUCKET = "bucket";
process.env.S3_REGION = "auto";
process.env.ASSET_CDN_URL = "https://worker-test.workers.dev";
- const { getAssetPath } = require("./get-asset-path");
+ const { getAssetPath } = await import("./get-asset-path");
expect(
getAssetPath({
...commonAsset,
diff --git a/packages/asset-uploader/tsconfig.json b/packages/asset-uploader/tsconfig.json
index b53cddcbf0..13e555ea69 100644
--- a/packages/asset-uploader/tsconfig.json
+++ b/packages/asset-uploader/tsconfig.json
@@ -3,7 +3,7 @@
"extends": "../../node_modules/@webstudio-is/tsconfig/base.json",
"include": ["src"],
"compilerOptions": {
- "module": "commonjs",
+ "module": "ES2020",
"target": "ES2020",
"strict": true,
"baseUrl": ".",
diff --git a/packages/css-data/package.json b/packages/css-data/package.json
index ed7a05d413..bc43e5eb6e 100644
--- a/packages/css-data/package.json
+++ b/packages/css-data/package.json
@@ -4,17 +4,18 @@
"description": "CSS Data",
"author": "Webstudio <[email protected]>",
"homepage": "https://webstudio.is",
+ "type": "module",
"scripts": {
"typecheck": "tsc --noEmit",
"checks": "yarn typecheck && yarn lint",
"dev": "tsup --watch",
- "build": "rm -fr lib tsconfig.tsbuildinfo && tsc",
+ "build:cjs": "tsc --module commonjs --outDir lib/cjs && find lib/cjs -name '*.js' | while read NAME; do mv $NAME ${NAME%.js}.cjs; done",
+ "build": "rm -fr lib tsconfig.tsbuildinfo && tsc && yarn build:cjs",
"build:mdn-data": "tsx ./bin/mdn-data.ts ./src",
"lint": "eslint ./src --ext .ts,.tsx --max-warnings 0"
},
"dependencies": {},
"devDependencies": {
- "@webstudio-is/jest-config": "*",
"mdn-data": "2.0.23",
"tsup": "^6.1.3",
"typescript": "4.7.4",
@@ -26,7 +27,10 @@
"peerDependencies": {
"zod": "^3.19.1"
},
- "main": "lib/index.js",
+ "exports": {
+ "import": "./lib/index.js",
+ "require": "./lib/cjs/index.cjs"
+ },
"types": "lib/index.d.ts",
"files": [
"lib/*",
@@ -40,7 +44,7 @@
"entry": [
"src/index.ts"
],
- "format": "cjs",
+ "format": "esm",
"outDir": "lib"
}
}
diff --git a/packages/css-data/tsconfig.json b/packages/css-data/tsconfig.json
index 0024dc5142..ecd0abd8a0 100644
--- a/packages/css-data/tsconfig.json
+++ b/packages/css-data/tsconfig.json
@@ -3,7 +3,7 @@
"extends": "../../node_modules/@webstudio-is/tsconfig/base.json",
"include": ["src"],
"compilerOptions": {
- "module": "commonjs",
+ "module": "ES2020",
"target": "ES2020",
"strict": true,
"baseUrl": ".",
diff --git a/packages/css-engine/.storybook/main.js b/packages/css-engine/.storybook/main.cjs
similarity index 100%
rename from packages/css-engine/.storybook/main.js
rename to packages/css-engine/.storybook/main.cjs
diff --git a/packages/css-engine/jest.config.js b/packages/css-engine/jest.config.js
index 4eeecbaf4e..e7fc137533 100644
--- a/packages/css-engine/jest.config.js
+++ b/packages/css-engine/jest.config.js
@@ -1 +1 @@
-module.exports = require("@webstudio-is/jest-config");
+export { default } from "@webstudio-is/jest-config";
diff --git a/packages/css-engine/package.json b/packages/css-engine/package.json
index fedf27cf4e..b78f5640d5 100644
--- a/packages/css-engine/package.json
+++ b/packages/css-engine/package.json
@@ -4,12 +4,13 @@
"description": "CSS Renderer for Webstudio",
"author": "Webstudio <[email protected]>",
"homepage": "https://webstudio.is",
+ "type": "module",
"scripts": {
"typecheck": "tsc --noEmit",
"checks": "yarn typecheck && yarn lint && yarn test",
"dev": "tsup --watch",
"build": "rm -fr lib tsconfig.tsbuildinfo && tsc",
- "test": "jest",
+ "test": "NODE_OPTIONS=--experimental-vm-modules jest",
"lint": "eslint ./src --ext .ts,.tsx --max-warnings 0",
"storybook:run": "start-storybook -p 6006",
"storybook:build": "build-storybook"
@@ -37,7 +38,7 @@
"@types/react": "^17.0.24",
"@types/react-dom": "^17.0.9"
},
- "main": "lib/index.js",
+ "exports": "./lib/index.js",
"types": "lib/index.d.ts",
"files": [
"lib/*",
@@ -51,7 +52,7 @@
"entry": [
"src/index.ts"
],
- "format": "cjs",
+ "format": "esm",
"outDir": "lib"
}
}
diff --git a/packages/css-engine/tsconfig.json b/packages/css-engine/tsconfig.json
index 54b8dc5d15..51bf8d0793 100644
--- a/packages/css-engine/tsconfig.json
+++ b/packages/css-engine/tsconfig.json
@@ -3,7 +3,7 @@
"extends": "../../node_modules/@webstudio-is/tsconfig/base.json",
"include": ["src"],
"compilerOptions": {
- "module": "commonjs",
+ "module": "ES2020",
"target": "ES2020",
"strict": true,
"baseUrl": ".",
diff --git a/packages/css-vars/package.json b/packages/css-vars/package.json
index 7004e6c9c4..174ed503ed 100644
--- a/packages/css-vars/package.json
+++ b/packages/css-vars/package.json
@@ -4,11 +4,13 @@
"description": "CSS vars utility",
"author": "Webstudio <[email protected]>",
"homepage": "https://webstudio.is",
+ "type": "module",
"scripts": {
"typecheck": "tsc --noEmit",
"checks": "yarn typecheck && yarn lint",
"dev": "tsup --watch",
- "build": "rm -fr lib tsconfig.tsbuildinfo && tsc",
+ "build:cjs": "tsc --module commonjs --outDir lib/cjs && find lib/cjs -name '*.js' | while read NAME; do mv $NAME ${NAME%.js}.cjs; done",
+ "build": "rm -fr lib tsconfig.tsbuildinfo && tsc && yarn build:cjs",
"lint": "eslint ./src --ext .ts,.tsx --max-warnings 0"
},
"dependencies": {},
@@ -17,7 +19,11 @@
"tsup": "^6.1.3",
"typescript": "4.7.4"
},
- "main": "lib/index.js",
+ "module": "./lib/index.js",
+ "exports": {
+ "import": "./lib/index.js",
+ "require": "./lib/cjs/index.cjs"
+ },
"types": "lib/index.d.ts",
"files": [
"lib/*",
@@ -31,7 +37,7 @@
"entry": [
"src/index.ts"
],
- "format": "cjs",
+ "format": "esm",
"outDir": "lib"
}
}
diff --git a/packages/css-vars/tsconfig.json b/packages/css-vars/tsconfig.json
index 0024dc5142..ecd0abd8a0 100644
--- a/packages/css-vars/tsconfig.json
+++ b/packages/css-vars/tsconfig.json
@@ -3,7 +3,7 @@
"extends": "../../node_modules/@webstudio-is/tsconfig/base.json",
"include": ["src"],
"compilerOptions": {
- "module": "commonjs",
+ "module": "ES2020",
"target": "ES2020",
"strict": true,
"baseUrl": ".",
diff --git a/packages/design-system/.storybook/main.js b/packages/design-system/.storybook/main.cjs
similarity index 100%
rename from packages/design-system/.storybook/main.js
rename to packages/design-system/.storybook/main.cjs
diff --git a/packages/design-system/jest.config.js b/packages/design-system/jest.config.js
index 4eeecbaf4e..e7fc137533 100644
--- a/packages/design-system/jest.config.js
+++ b/packages/design-system/jest.config.js
@@ -1 +1 @@
-module.exports = require("@webstudio-is/jest-config");
+export { default } from "@webstudio-is/jest-config";
diff --git a/packages/design-system/package.json b/packages/design-system/package.json
index 0d6950bcd2..a417063be1 100644
--- a/packages/design-system/package.json
+++ b/packages/design-system/package.json
@@ -4,12 +4,13 @@
"description": "Webstudio Design System",
"author": "Webstudio <[email protected]>",
"homepage": "https://webstudio.is",
+ "type": "module",
"scripts": {
"dev": "tsup --watch",
"build": "rm -fr lib tsconfig.tsbuildinfo && tsc",
"typecheck": "tsc --noEmit",
"lint": "eslint ./src --ext .ts,.tsx --max-warnings 0",
- "test": "jest",
+ "test": "NODE_OPTIONS=--experimental-vm-modules jest",
"checks": "yarn typecheck && yarn lint && yarn test",
"storybook:run": "start-storybook -p 6006",
"storybook:build": "build-storybook"
@@ -68,7 +69,7 @@
"@webstudio-is/icons": "*",
"react-hot-toast": "^2.3.0"
},
- "main": "lib/index.js",
+ "exports": "./lib/index.js",
"types": "lib/index.d.ts",
"files": [
"lib/*",
@@ -82,7 +83,7 @@
"entry": [
"src/index.ts"
],
- "format": "cjs",
+ "format": "esm",
"outDir": "lib"
}
}
diff --git a/packages/design-system/tsconfig.json b/packages/design-system/tsconfig.json
index ba30483254..cbd662b720 100644
--- a/packages/design-system/tsconfig.json
+++ b/packages/design-system/tsconfig.json
@@ -4,7 +4,7 @@
"include": ["src"],
"compilerOptions": {
"lib": ["DOM", "DOM.Iterable", "ES2020"],
- "module": "commonjs",
+ "module": "ES2020",
"jsx": "react-jsx",
"target": "ES2020",
"strict": true,
diff --git a/packages/fonts/jest.config.js b/packages/fonts/jest.config.js
index 4eeecbaf4e..e7fc137533 100644
--- a/packages/fonts/jest.config.js
+++ b/packages/fonts/jest.config.js
@@ -1 +1 @@
-module.exports = require("@webstudio-is/jest-config");
+export { default } from "@webstudio-is/jest-config";
diff --git a/packages/fonts/package.json b/packages/fonts/package.json
index b6fc4078c3..4d23b50da6 100644
--- a/packages/fonts/package.json
+++ b/packages/fonts/package.json
@@ -4,9 +4,10 @@
"description": "Fonts utils",
"author": "Webstudio <[email protected]>",
"homepage": "https://webstudio.is",
+ "type": "module",
"scripts": {
"typecheck": "tsc --noEmit",
- "test": "jest",
+ "test": "NODE_OPTIONS=--experimental-vm-modules jest",
"checks": "yarn typecheck && yarn lint && yarn test",
"dev": "tsup --watch",
"build": "rm -fr lib tsconfig.tsbuildinfo && tsc",
@@ -16,17 +17,21 @@
"fontkit": "^2.0.2"
},
"devDependencies": {
+ "@types/fontkit": "^2.0.0",
"@webstudio-is/design-system": "*",
"@webstudio-is/jest-config": "*",
"tsup": "^6.1.3",
"typescript": "4.7.4",
- "@types/fontkit": "^1.8.0",
"zod": "^3.19.1"
},
"peerDependencies": {
"zod": "^3.19.1"
},
- "main": "lib/index.js",
+ "module": "./lib/index.js",
+ "exports": {
+ ".": "./lib/index.js",
+ "./server": "./server.js"
+ },
"types": "lib/index.d.ts",
"files": [
"lib/*",
@@ -41,7 +46,7 @@
"src/index.ts",
"src/index.server.ts"
],
- "format": "cjs",
+ "format": "esm",
"outDir": "lib"
}
}
diff --git a/packages/fonts/server.js b/packages/fonts/server.js
index 928878beec..a6fbe7c12c 100644
--- a/packages/fonts/server.js
+++ b/packages/fonts/server.js
@@ -1 +1 @@
-module.exports = require("./lib/index.server");
+export * from "./lib/index.server";
diff --git a/packages/fonts/src/font-data.ts b/packages/fonts/src/font-data.ts
index 94fe4fd200..ec786df716 100644
--- a/packages/fonts/src/font-data.ts
+++ b/packages/fonts/src/font-data.ts
@@ -1,5 +1,5 @@
import type { FontFormat } from "./types";
-import fontkit from "fontkit";
+import { create as createFontKit } from "fontkit";
import { FontWeight, fontWeights } from "./font-weights";
// @todo sumbit this to definitely typed, they are not up to date
@@ -59,7 +59,7 @@ type FontData = {
};
export const getFontData = (data: Uint8Array): FontData => {
- const font = fontkit.create(data as Buffer);
+ const font = createFontKit(data as Buffer);
const format = font.type.toLowerCase() as FontData["format"];
const originalFamily = font.getName("fontFamily");
const subfamily =
diff --git a/packages/fonts/tsconfig.json b/packages/fonts/tsconfig.json
index 53af47871e..c175851463 100644
--- a/packages/fonts/tsconfig.json
+++ b/packages/fonts/tsconfig.json
@@ -3,7 +3,7 @@
"extends": "../../node_modules/@webstudio-is/tsconfig/base.json",
"include": ["src"],
"compilerOptions": {
- "module": "commonjs",
+ "module": "ES2020",
"target": "ES2020",
"strict": true,
"baseUrl": ".",
diff --git a/packages/icons/.storybook/main.js b/packages/icons/.storybook/main.cjs
similarity index 100%
rename from packages/icons/.storybook/main.js
rename to packages/icons/.storybook/main.cjs
diff --git a/packages/icons/package.json b/packages/icons/package.json
index 24050a4735..5c20fc42bb 100644
--- a/packages/icons/package.json
+++ b/packages/icons/package.json
@@ -4,9 +4,11 @@
"description": "Webstudio Icons",
"author": "Webstudio <[email protected]>",
"homepage": "https://webstudio.is",
+ "type": "module",
"scripts": {
"dev": "tsup --watch",
- "build": "rm -fr lib tsconfig.tsbuildinfo && tsc",
+ "build:cjs": "tsc --module commonjs --outDir lib/cjs && find lib/cjs -name '*.js' | while read NAME; do mv $NAME ${NAME%.js}.cjs; done",
+ "build": "rm -fr lib tsconfig.tsbuildinfo && tsc && yarn build:cjs",
"generate": "rm -fr src/gen && NODE_OPTIONS='--loader=tsx' svgo-jsx svgo-jsx.config.ts",
"typecheck": "tsc --noEmit",
"lint": "eslint ./src --ext .ts,.tsx --max-warnings 0",
@@ -37,7 +39,11 @@
"@radix-ui/react-icons": "^1.1.0",
"@webstudio-is/css-vars": "*"
},
- "main": "lib/index.js",
+ "module": "./lib/index.js",
+ "exports": {
+ "import": "./lib/index.js",
+ "require": "./lib/cjs/index.cjs"
+ },
"types": "lib/index.d.ts",
"files": [
"lib/*",
@@ -51,7 +57,7 @@
"entry": [
"src/index.ts"
],
- "format": "cjs",
+ "format": "esm",
"outDir": "lib"
}
}
diff --git a/packages/icons/tsconfig.json b/packages/icons/tsconfig.json
index 66c4373f0b..05b1877afe 100644
--- a/packages/icons/tsconfig.json
+++ b/packages/icons/tsconfig.json
@@ -4,7 +4,7 @@
"include": ["src"],
"compilerOptions": {
"lib": ["DOM", "DOM.Iterable", "ES2020"],
- "module": "commonjs",
+ "module": "es2020",
"jsx": "react-jsx",
"target": "ES2020",
"strict": true,
diff --git a/packages/jest-config/index.js b/packages/jest-config/index.js
index 4ef0eeb650..4d00255cf3 100644
--- a/packages/jest-config/index.js
+++ b/packages/jest-config/index.js
@@ -6,10 +6,9 @@ module.exports = {
testMatch: ["<rootDir>/src/**/*.test.ts"],
transform: {
"^.+\\.tsx?$": [
- require.resolve("babel-jest"),
+ require.resolve("esbuild-jest"),
{
- presets: ["@babel/typescript", "@babel/react"],
- plugins: ["@babel/transform-modules-commonjs"],
+ format: "esm",
},
],
"^.+\\.webp$": require.resolve("./file-transform.js"),
@@ -17,4 +16,5 @@ module.exports = {
moduleNameMapper: {
"^~/(.*)$": "<rootDir>/src/$1",
},
+ extensionsToTreatAsEsm: [".ts", ".tsx"],
};
diff --git a/packages/jest-config/package.json b/packages/jest-config/package.json
index b860cd109e..e749e93caa 100644
--- a/packages/jest-config/package.json
+++ b/packages/jest-config/package.json
@@ -3,12 +3,8 @@
"version": "1.0.2",
"license": "MIT",
"dependencies": {
- "@babel/core": "^7.20.2",
- "@babel/plugin-transform-modules-commonjs": "^7.19.6",
- "@babel/preset-react": "^7.18.6",
- "@babel/preset-typescript": "^7.18.6",
"@types/jest": "^29.2.3",
- "babel-jest": "^29.3.1",
+ "esbuild-jest": "^0.5.0",
"jest": "^29.3.1"
},
"publishConfig": {
diff --git a/packages/prisma-client/migrations-cli/umzug.ts b/packages/prisma-client/migrations-cli/umzug.ts
index 5345ed0f7c..41e341a780 100755
--- a/packages/prisma-client/migrations-cli/umzug.ts
+++ b/packages/prisma-client/migrations-cli/umzug.ts
@@ -37,7 +37,7 @@ export const umzug = new Umzug({
prismaMigrations.generateMigrationClient(params.name);
// eslint-disable-next-line @typescript-eslint/no-var-requires
- const migration = require(tsFilePath);
+ const migration = await import(tsFilePath);
if (typeof migration.default !== "function") {
throw new UserError(
diff --git a/packages/prisma-client/package.json b/packages/prisma-client/package.json
index addc2f7bcf..ab3b0d7d26 100644
--- a/packages/prisma-client/package.json
+++ b/packages/prisma-client/package.json
@@ -4,6 +4,7 @@
"description": "Webstudio Prisma layer",
"author": "Webstudio <[email protected]>",
"homepage": "https://webstudio.is",
+ "type": "module",
"scripts": {
"typecheck": "tsc --noEmit",
"lint": "eslint ./src --ext .ts,.tsx --max-warnings 0",
@@ -22,7 +23,7 @@
"typescript": "4.7.4",
"zod": "^3.19.1"
},
- "main": "lib/index.js",
+ "exports": "./lib/index.js",
"types": "lib/index.d.ts",
"license": "MIT",
"private": false,
@@ -45,7 +46,7 @@
"entry": [
"src/index.ts"
],
- "format": "cjs",
+ "format": "esm",
"outDir": "lib"
}
}
diff --git a/packages/prisma-client/tsconfig.json b/packages/prisma-client/tsconfig.json
index 11bd4f21c3..eb8619773c 100644
--- a/packages/prisma-client/tsconfig.json
+++ b/packages/prisma-client/tsconfig.json
@@ -3,7 +3,7 @@
"extends": "../../node_modules/@webstudio-is/tsconfig/base.json",
"include": ["src"],
"compilerOptions": {
- "module": "commonjs",
+ "module": "ES2020",
"target": "ES2019",
"strict": true,
"baseUrl": ".",
diff --git a/packages/project/jest.config.js b/packages/project/jest.config.js
index 4eeecbaf4e..e7fc137533 100644
--- a/packages/project/jest.config.js
+++ b/packages/project/jest.config.js
@@ -1 +1 @@
-module.exports = require("@webstudio-is/jest-config");
+export { default } from "@webstudio-is/jest-config";
diff --git a/packages/project/package.json b/packages/project/package.json
index e0df9ba370..db225a512e 100644
--- a/packages/project/package.json
+++ b/packages/project/package.json
@@ -4,12 +4,14 @@
"description": "Webstudio Project",
"author": "Webstudio <[email protected]>",
"homepage": "https://webstudio.is",
+ "type": "module",
"scripts": {
"typecheck": "tsc --noEmit",
- "test": "jest",
+ "test": "NODE_OPTIONS=--experimental-vm-modules jest",
"checks": "yarn typecheck && yarn lint && yarn test",
"dev": "tsup --watch",
- "build": "rm -fr lib tsconfig.tsbuildinfo && tsc",
+ "build:cjs": "tsc --module commonjs --outDir lib/cjs && find lib/cjs -name '*.js' | while read NAME; do mv $NAME ${NAME%.js}.cjs; done",
+ "build": "rm -fr lib tsconfig.tsbuildinfo && tsc && yarn build:cjs",
"lint": "eslint ./src --ext .ts,.tsx --max-warnings 0"
},
"dependencies": {
@@ -28,7 +30,13 @@
"tsup": "^6.1.3",
"typescript": "4.7.4"
},
- "main": "lib/index.js",
+ "exports": {
+ ".": {
+ "import": "./lib/index.js",
+ "require": "./lib/cjs/index.cjs"
+ },
+ "./server": "./server.js"
+ },
"types": "lib/index.d.ts",
"files": [
"lib/*",
@@ -43,7 +51,7 @@
"src/index.ts",
"src/index.server.ts"
],
- "format": "cjs",
+ "format": "esm",
"outDir": "lib"
}
}
diff --git a/packages/project/server.js b/packages/project/server.js
index 928878beec..a6fbe7c12c 100644
--- a/packages/project/server.js
+++ b/packages/project/server.js
@@ -1 +1 @@
-module.exports = require("./lib/index.server");
+export * from "./lib/index.server";
diff --git a/packages/project/tsconfig.json b/packages/project/tsconfig.json
index cd49443b6e..4a0964f60b 100644
--- a/packages/project/tsconfig.json
+++ b/packages/project/tsconfig.json
@@ -3,7 +3,7 @@
"extends": "../../node_modules/@webstudio-is/tsconfig/base.json",
"include": ["src"],
"compilerOptions": {
- "module": "commonjs",
+ "module": "ES2020",
"target": "ES2020",
"strict": true,
"baseUrl": ".",
diff --git a/packages/react-sdk/.storybook/main.js b/packages/react-sdk/.storybook/main.cjs
similarity index 100%
rename from packages/react-sdk/.storybook/main.js
rename to packages/react-sdk/.storybook/main.cjs
diff --git a/packages/react-sdk/jest.config.js b/packages/react-sdk/jest.config.js
index 4eeecbaf4e..e7fc137533 100644
--- a/packages/react-sdk/jest.config.js
+++ b/packages/react-sdk/jest.config.js
@@ -1 +1 @@
-module.exports = require("@webstudio-is/jest-config");
+export { default } from "@webstudio-is/jest-config";
diff --git a/packages/react-sdk/package.json b/packages/react-sdk/package.json
index d3d92aa43b..efc19a914b 100644
--- a/packages/react-sdk/package.json
+++ b/packages/react-sdk/package.json
@@ -4,13 +4,15 @@
"description": "Webstudio JavaScript / TypeScript API",
"author": "Webstudio <[email protected]>",
"homepage": "https://webstudio.is",
+ "type": "module",
"scripts": {
"dev": "tsup --watch",
"build": "yarn build:lib",
"build:args": "tsx ./bin/generate-arg-types.ts './src/components/*.tsx !./src/**/*.stories.tsx !./src/**/*.ws.tsx'",
"typecheck": "tsc --noEmit",
- "build:lib": "rm -fr lib tsconfig.tsbuildinfo && tsc",
- "test": "jest",
+ "build:cjs": "tsc --module commonjs --outDir lib/cjs && find lib/cjs -name '*.js' | while read NAME; do mv $NAME ${NAME%.js}.cjs; done",
+ "build:lib": "rm -fr lib tsconfig.tsbuildinfo && tsc && yarn build:cjs",
+ "test": "NODE_OPTIONS=--experimental-vm-modules jest",
"lint": "eslint ./src --ext .ts,.tsx --max-warnings 0",
"checks": "yarn typecheck && yarn lint && yarn test",
"prepublishOnly": "yarn checks && yarn build:lib",
@@ -67,7 +69,10 @@
"react-nano-state": "^0.4.0",
"warn-once": "^0.1.1"
},
- "main": "lib/index.js",
+ "exports": {
+ "import": "./lib/index.js",
+ "require": "./lib/cjs/index.cjs"
+ },
"types": "lib/index.d.ts",
"files": [
"lib/*",
@@ -81,7 +86,7 @@
"entry": [
"src/index.ts"
],
- "format": "cjs",
+ "format": "esm",
"outDir": "lib"
}
}
diff --git a/packages/react-sdk/tsconfig.json b/packages/react-sdk/tsconfig.json
index 059cfd6a19..840839883c 100644
--- a/packages/react-sdk/tsconfig.json
+++ b/packages/react-sdk/tsconfig.json
@@ -4,7 +4,7 @@
"include": ["./src", "./src/**/*.json", "./@types/**/*.d.ts"],
"compilerOptions": {
"lib": ["DOM", "DOM.Iterable", "ES2020"],
- "module": "commonjs",
+ "module": "ES2020",
"jsx": "react-jsx",
"target": "ES2020",
"strict": true,
diff --git a/yarn.lock b/yarn.lock
index 6ad8f43015..fcbbbb3d82 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -1670,7 +1670,7 @@
"@babel/helper-plugin-utils" "^7.18.6"
babel-plugin-dynamic-import-node "^2.3.3"
-"@babel/plugin-transform-modules-commonjs@^7.12.13", "@babel/plugin-transform-modules-commonjs@^7.13.8", "@babel/plugin-transform-modules-commonjs@^7.18.6", "@babel/plugin-transform-modules-commonjs@^7.19.6":
+"@babel/plugin-transform-modules-commonjs@^7.12.13", "@babel/plugin-transform-modules-commonjs@^7.13.8", "@babel/plugin-transform-modules-commonjs@^7.18.6":
version "7.19.6"
resolved "https://registry.yarnpkg.com/@babel/plugin-transform-modules-commonjs/-/plugin-transform-modules-commonjs-7.19.6.tgz#25b32feef24df8038fc1ec56038917eacb0b730c"
integrity sha512-8PIa1ym4XRTKuSsOUXqDG0YaOlEuTVvHMe5JCfgBMOtHvJKw/4NGovEGN33viISshG/rZNVrACiBmPQLvWN8xQ==
@@ -1944,7 +1944,7 @@
"@babel/types" "^7.4.4"
esutils "^2.0.2"
-"@babel/preset-react@^7.12.10", "@babel/preset-react@^7.18.6":
+"@babel/preset-react@^7.12.10":
version "7.18.6"
resolved "https://registry.yarnpkg.com/@babel/preset-react/-/preset-react-7.18.6.tgz#979f76d6277048dc19094c217b507f3ad517dd2d"
integrity sha512-zXr6atUmyYdiWRVLOZahakYmOBHtWc2WGCkP8PYTgZi0iJXDY2CN180TdrIW4OGOAdLc7TifzDIvtx6izaRIzg==
@@ -1956,7 +1956,7 @@
"@babel/plugin-transform-react-jsx-development" "^7.18.6"
"@babel/plugin-transform-react-pure-annotations" "^7.18.6"
-"@babel/preset-typescript@^7.12.7", "@babel/preset-typescript@^7.13.0", "@babel/preset-typescript@^7.17.12", "@babel/preset-typescript@^7.18.6":
+"@babel/preset-typescript@^7.12.7", "@babel/preset-typescript@^7.13.0", "@babel/preset-typescript@^7.17.12":
version "7.18.6"
resolved "https://registry.yarnpkg.com/@babel/preset-typescript/-/preset-typescript-7.18.6.tgz#ce64be3e63eddc44240c6358daefac17b3186399"
integrity sha512-s9ik86kXBAnD760aybBucdpnLsAt0jK1xqJn2juOn9lkOvSHV60os5hxoVJsPzMQxvnUJFAlkont2DvvaYEBtQ==
@@ -5253,10 +5253,10 @@
resolved "https://registry.yarnpkg.com/@types/estree/-/estree-0.0.51.tgz#cfd70924a25a3fd32b218e5e420e6897e1ac4f40"
integrity sha512-CuPgU6f3eT/XgKKPqKd/gLZV1Xmvf1a2R5POBOGQa6uv82xpls89HU5zKeVoyR8XzHd1RGNOlQlvUe3CFkjWNQ==
-"@types/fontkit@^1.8.0":
- version "1.8.0"
- resolved "https://registry.yarnpkg.com/@types/fontkit/-/fontkit-1.8.0.tgz#2c100c8eada6f7403c3b740602f771bea4fd7971"
- integrity sha512-hLlxFWmyMkWyJiO/RVc8L5OVxHXzoyH0ZKZsUQkhlKwUdUtwb77u7jjxVtdTpFHaAtfifbA8CQ4/QjcQcLiwDw==
+"@types/fontkit@^2.0.0":
+ version "2.0.0"
+ resolved "https://registry.yarnpkg.com/@types/fontkit/-/fontkit-2.0.0.tgz#1bde268783f681ff98b40031f9011a5c6045d91f"
+ integrity sha512-Qe+6szpPLTNsqkDFs2MScJyB51d5Hpobyg/T0QoUWO53WuNOTNLsV8fkE4QQPOJbhOMN5wlwmNeDdsh/e6Uqdg==
dependencies:
"@types/node" "*"