Skip to content

Commit

Permalink
Add support for transpiling ESM code (and convert this repo itself to…
Browse files Browse the repository at this point in the history
… ESM)
  • Loading branch information
airhorns committed Sep 28, 2024
1 parent 39abfa8 commit 7246f8d
Show file tree
Hide file tree
Showing 52 changed files with 3,613 additions and 4,151 deletions.
48 changes: 48 additions & 0 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
module.exports = {
extends: "@gadgetinc/eslint-config",
parserOptions: {
tsconfigRootDir: __dirname,
project: ["./tsconfig.test.json"],
},
ignorePatterns: [".eslintrc.cjs", "spec/fixtures/**/*"],
rules: {
"lodash/import-scope": "off",
// Disable all Jest-related ESLint rules
"jest/no-alias-methods": "off",
"jest/no-commented-out-tests": "off",
"jest/no-conditional-expect": "off",
"jest/no-deprecated-functions": "off",
"jest/no-disabled-tests": "off",
"jest/no-done-callback": "off",
"jest/no-duplicate-hooks": "off",
"jest/no-export": "off",
"jest/no-focused-tests": "off",
"jest/no-hooks": "off",
"jest/no-identical-title": "off",
"jest/no-if": "off",
"jest/no-interpolation-in-snapshots": "off",
"jest/no-jasmine-globals": "off",
"jest/no-jest-import": "off",
"jest/no-large-snapshots": "off",
"jest/no-mocks-import": "off",
"jest/no-restricted-matchers": "off",
"jest/no-standalone-expect": "off",
"jest/no-test-prefixes": "off",
"jest/no-test-return-statement": "off",
"jest/prefer-called-with": "off",
"jest/prefer-expect-assertions": "off",
"jest/prefer-hooks-on-top": "off",
"jest/prefer-spy-on": "off",
"jest/prefer-strict-equal": "off",
"jest/prefer-to-be": "off",
"jest/prefer-to-contain": "off",
"jest/prefer-to-have-length": "off",
"jest/prefer-todo": "off",
"jest/require-to-throw-message": "off",
"jest/require-top-level-describe": "off",
"jest/valid-describe-callback": "off",
"jest/valid-expect": "off",
"jest/valid-expect-in-promise": "off",
"jest/valid-title": "off"
},
};
15 changes: 0 additions & 15 deletions .eslintrc.js

This file was deleted.

2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
- uses: ./.github/actions/setup-test-env
- run: pnpm build
- run: integration-test/test.sh
- run: pnpm jest
- run: pnpm test

lint:
runs-on: ubuntu-latest
Expand Down
12 changes: 6 additions & 6 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
packages =
rec {
bash = pkgs.bash;
nodejs = pkgs.nodejs_20;
nodejs = pkgs.nodejs_22;
corepack = pkgs.corepack;
};

Expand Down
4 changes: 2 additions & 2 deletions gitpkg.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const { execSync } = require('child_process')
import { execSync } from "child_process";

module.exports = () => ({
export default () => ({
getTagName: (pkg) =>
`${pkg.name}-v${pkg.version}-gitpkg-${execSync(
'git rev-parse --short HEAD',
Expand Down
11 changes: 11 additions & 0 deletions integration-test/esm-js-from-ts/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"name": "esm-js-from-ts",
"version": "1.0.0",
"description": "",
"main": "index.js",
"type": "module",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"license": "ISC"
}
3 changes: 3 additions & 0 deletions integration-test/esm-js-from-ts/run.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { utility } from "./utils.js";

console.log(utility("It worked!"));
File renamed without changes.
1 change: 1 addition & 0 deletions integration-test/esm-js-from-ts/utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const utility = (str) => str.toUpperCase();
11 changes: 11 additions & 0 deletions integration-test/esm-ts-from-js/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"name": "esm-ts-from-js",
"version": "1.0.0",
"description": "",
"main": "index.js",
"type": "module",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"license": "ISC"
}
3 changes: 3 additions & 0 deletions integration-test/esm-ts-from-js/run.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { utility } from "./utils.js";

console.log(utility("It worked!"));
5 changes: 5 additions & 0 deletions integration-test/esm-ts-from-js/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env bash
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
set -ex

$DIR/../../pkg/wds.bin.js $@ $DIR/run.js | grep "IT WORKED"
File renamed without changes.
11 changes: 11 additions & 0 deletions integration-test/esm-ts-from-ts/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"name": "simple-esm",
"version": "1.0.0",
"description": "",
"main": "index.js",
"type": "module",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"license": "ISC"
}
3 changes: 3 additions & 0 deletions integration-test/esm-ts-from-ts/run.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { utility } from "./utils.js";

console.log(utility("It worked!"));
5 changes: 5 additions & 0 deletions integration-test/esm-ts-from-ts/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env bash
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
set -ex

$DIR/../../pkg/wds.bin.js $@ $DIR/run.ts | grep "IT WORKED"
1 change: 1 addition & 0 deletions integration-test/esm-ts-from-ts/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const utility = (str: string) => str.toUpperCase();
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"version": "1.0.0",
"description": "",
"main": "index.js",
"type": "commonjs",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
Expand Down
File renamed without changes.
5 changes: 5 additions & 0 deletions integration-test/simple-cjs/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env bash
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
set -ex

$DIR/../../pkg/wds.bin.js $@ $DIR/run.ts | grep "IT WORKED"
1 change: 1 addition & 0 deletions integration-test/simple-cjs/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const utility = (str: string) => str.toUpperCase();
1 change: 1 addition & 0 deletions integration-test/sourcemap/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
"version": "1.0.0",
"description": "",
"main": "index.js",
"type": "commonjs",
"license": "ISC"
}
19 changes: 17 additions & 2 deletions integration-test/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,23 @@ DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
echo $DIR
set -e

echo "::group::Simple test ${args}"
$DIR/simple/test.sh $args
echo "::group::Simple CJS test ${args}"
$DIR/simple-cjs/test.sh $args
echo "::endgroup::"
echo

echo "::group::ESM TS from TS import test ${args}"
$DIR/esm-ts-from-ts/test.sh $args
echo "::endgroup::"
echo

echo "::group::ESM JS from TS import test ${args}"
$DIR/esm-js-from-ts/test.sh $args
echo "::endgroup::"
echo

echo "::group::ESM TS from JS import test ${args}"
$DIR/esm-ts-from-js/test.sh $args
echo "::endgroup::"
echo

Expand Down
7 changes: 0 additions & 7 deletions jest.config.js

This file was deleted.

26 changes: 13 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "wds",
"version": "0.20.0",
"version": "0.21.0",
"author": "Harry Brundage",
"license": "MIT",
"bin": {
Expand All @@ -14,6 +14,7 @@
"access": "public"
},
"types": "pkg/index.d.ts",
"type": "module",
"main": "pkg/index.js",
"files": [
"pkg/*",
Expand All @@ -31,7 +32,8 @@
"lint:eslint": "NODE_OPTIONS=\"--max-old-space-size=4096\" eslint --quiet --ext ts,tsx src",
"lint:fix": "NODE_OPTIONS=\"--max-old-space-size=4096\" prettier --write --check \"src/**/*.{js,ts,tsx}\" && eslint --ext ts,tsx --fix src",
"prerelease": "gitpkg publish",
"test": "jest"
"test": "vitest run",
"test:watch": "vitest"
},
"engines": {
"node": ">=16.0.0"
Expand All @@ -42,31 +44,29 @@
"chokidar": "^3.5.3",
"find-root": "^1.1.0",
"find-yarn-workspace-root": "^2.0.0",
"fs-extra": "^11.2.0",
"globby": "^11.1.0",
"graceful-fs": "^4.2.11",
"lodash": "^4.17.20",
"oxc-resolver": "^1.12.0",
"pkg-dir": "^5.0.0",
"write-file-atomic": "^6.0.0",
"yargs": "^16.2.0"
},
"devDependencies": {
"@gadgetinc/eslint-config": "^0.6.1",
"@gadgetinc/prettier-config": "^0.4.0",
"@swc/jest": "^0.2.36",
"@types/find-root": "^1.1.2",
"@types/graceful-fs": "^4.1.9",
"@types/jest": "^27.4.0",
"@types/fs-extra": "^11.0.4",
"@types/lodash": "^4.14.194",
"@types/node": "^18.11.9",
"@types/node": "^22.7.4",
"@types/write-file-atomic": "^4.0.3",
"@types/yargs": "^15.0.14",
"eslint": "^8.40.0",
"eslint-plugin-jest": "^27.2.1",
"gitpkg": "^1.0.0-beta.2",
"jest": "^27.4.7",
"eslint": "^8.57.1",
"gitpkg": "github:airhorns/gitpkg#gitpkg-v1.0.0-beta.4-gitpkg-82083c3",
"prettier": "^2.8.8",
"typescript": "^5.1.3",
"typescript": "^5.6.2",
"vitest": "^2.1.1",
"zx": "^7.2.3"
},
"packageManager": "pnpm@8.12.1+sha256.28ca61ece5a496148b73fabc9afb820f9c3fec4f55f04ce45a2cea0a5219f2e1"
"packageManager": "pnpm@9.11.0+sha512.0a203ffaed5a3f63242cd064c8fb5892366c103e328079318f78062f24ea8c9d50bc6a47aa3567cabefd824d170e78fa2745ed1f16b132e16436146b7688f19b"
}
Loading

0 comments on commit 7246f8d

Please sign in to comment.