Skip to content

Commit 352f53c

Browse files
authored
Migrate from CJS to ESM (#286)
* refactor: fix to jumpable links * chore!: migrate CJS to ESM * add changelog * refactor: fix lint errors * refactor: do not use `__dirname` in ESM * add comment for workaround * chore!: migrate several files from CJS to ESM
1 parent 0bf647b commit 352f53c

23 files changed

Lines changed: 48 additions & 31 deletions

.changeset/config.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"$schema": "https://unpkg.com/@changesets/config@3.1.1/schema.json",
3-
"changelog": ["./custom-changelog-github.mts", { "repo": "mizdra/css-modules-kit" }],
3+
"changelog": ["./custom-changelog-github.ts", { "repo": "mizdra/css-modules-kit" }],
44
"commit": false,
55
"fixed": [],
66
"linked": [],

.changeset/major-friends-pick.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@css-modules-kit/ts-plugin': minor
3+
---
4+
5+
chore: migrate modules other than entry points from CJS to ESM

.changeset/sweet-tools-press.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
'@css-modules-kit/stylelint-plugin': minor
3+
'@css-modules-kit/eslint-plugin': minor
4+
'@css-modules-kit/codegen': minor
5+
'css-modules-kit-vscode': minor
6+
'@css-modules-kit/core': minor
7+
---
8+
9+
chore: migrate from CJS to ESM

.vscode-test.cjs renamed to .vscode-test.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,21 @@
1-
const { defineConfig } = require('@vscode/test-cli');
1+
import { defineConfig } from '@vscode/test-cli';
22

33
const baseConfig = /** @type {Parameters<typeof defineConfig>[0]} */ ({
44
extensionDevelopmentPath: 'packages/vscode',
55
version: process.env.VSCODE_VERSION ?? 'stable',
66
mocha: {
77
timeout: 30_000,
8+
// If the test file is ESM, importing 'vscode' can cause a deadlock.
9+
// ref: https://github.com/microsoft/vscode-test-cli/issues/77#issuecomment-3696907905
10+
// Therefore, we transpile with tsx to CJS before executing.
811
require: ['tsx/cjs', './scripts/vscode-test-setup.ts'],
912
},
1013
download: {
1114
timeout: 60_000,
1215
},
1316
});
1417

15-
module.exports = defineConfig([
18+
export default defineConfig([
1619
{
1720
...baseConfig,
1821
label: 'open-css-file',

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/codegen/e2e-test/index.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import dedent from 'dedent';
55
import { expect, test } from 'vitest';
66
import { createIFF } from '../src/test/fixture.js';
77

8-
const binPath = join(__dirname, '../bin/cmk.mjs');
9-
const tscPath = join(__dirname, '../../../node_modules/typescript/bin/tsc');
8+
const binPath = join(import.meta.dirname, '../bin/cmk.js');
9+
const tscPath = join(import.meta.dirname, '../../../node_modules/typescript/bin/tsc');
1010

1111
test('generates .d.ts', async () => {
1212
const iff = await createIFF({

packages/codegen/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "@css-modules-kit/codegen",
33
"description": "A tool for generating `*.d.ts` files for `*.module.css`.",
44
"version": "0.7.0",
5-
"type": "commonjs",
5+
"type": "module",
66
"sideEffects": false,
77
"repository": {
88
"type": "git",
@@ -23,7 +23,7 @@
2323
"registry": "https://registry.npmjs.org/"
2424
},
2525
"bin": {
26-
"cmk": "bin/cmk.mjs"
26+
"cmk": "bin/cmk.js"
2727
},
2828
"keywords": [
2929
"css-modules",

packages/codegen/src/cli.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { parseArgs } from 'node:util';
22
import { resolve } from '@css-modules-kit/core';
3-
import packageJson from '../package.json';
3+
import packageJson from '../package.json' with { type: 'json' };
44
import { ParseCLIArgsError } from './error.js';
55

66
const helpText = `

0 commit comments

Comments
 (0)