From e0783e526ca267f9caafccdd885e2595c9025dc2 Mon Sep 17 00:00:00 2001 From: Gustavo Perdomo Date: Fri, 12 Jul 2024 20:16:55 -0400 Subject: [PATCH] feat(nx-set-shas): compiled using swc --- nx.json | 5 +++++ package-lock.json | 35 ++++++++++++++++++++++++++++- package.json | 3 ++- packages/nx-set-shas/.swcrc | 29 ++++++++++++++++++++++++ packages/nx-set-shas/jest.config.ts | 19 +++++++++++++++- packages/nx-set-shas/package.json | 6 ++--- packages/nx-set-shas/project.json | 2 +- packages/nx-set-shas/src/index.ts | 1 + 8 files changed, 93 insertions(+), 7 deletions(-) create mode 100644 packages/nx-set-shas/.swcrc diff --git a/nx.json b/nx.json index 4062e26a..b90b699b 100644 --- a/nx.json +++ b/nx.json @@ -16,6 +16,11 @@ }, "nxCloudAccessToken": "YTA4ZDcwNjQtMDZmNC00YjUyLTk5ZTMtN2E1ZDE1ZTkwMWYxfHJlYWQ=", "targetDefaults": { + "@nx/js:swc": { + "cache": true, + "dependsOn": ["^build"], + "inputs": ["production", "^production"] + }, "@nx/js:tsc": { "cache": true, "dependsOn": ["^build"], diff --git a/package-lock.json b/package-lock.json index 50f2f815..d1357393 100644 --- a/package-lock.json +++ b/package-lock.json @@ -15,7 +15,6 @@ "@nx/devkit": "19.4.3", "@octokit/openapi-types": "22.1.0", "@renovate/pep440": "1.0.0", - "@swc/helpers": "0.5.11", "chalk": "4.1.2", "ci-info": "4.0.0", "clipanion": "4.0.0-rc.3", @@ -44,6 +43,8 @@ "@swc-node/register": "1.9.2", "@swc/cli": "0.3.12", "@swc/core": "1.5.7", + "@swc/helpers": "~0.5.11", + "@swc/jest": "~0.2.36", "@types/jest": "29.5.6", "@types/node": "18.19.31", "@types/semver": "7.5.8", @@ -3435,6 +3436,19 @@ "node": ">=8" } }, + "node_modules/@jest/create-cache-key-function": { + "version": "29.7.0", + "resolved": "https://registry.npmjs.org/@jest/create-cache-key-function/-/create-cache-key-function-29.7.0.tgz", + "integrity": "sha512-4QqS3LY5PBmTRHj9sAg1HLoPzqAI0uOX6wI/TRqHIcOxlFidy6YEmCQJk6FSZjNLGCeubDMfmkWL+qaLKhSGQA==", + "dev": true, + "license": "MIT", + "dependencies": { + "@jest/types": "^29.6.3" + }, + "engines": { + "node": "^14.15.0 || ^16.10.0 || >=18.0.0" + } + }, "node_modules/@jest/environment": { "version": "29.7.0", "resolved": "https://registry.npmjs.org/@jest/environment/-/environment-29.7.0.tgz", @@ -4865,11 +4879,30 @@ "version": "0.5.11", "resolved": "https://registry.npmjs.org/@swc/helpers/-/helpers-0.5.11.tgz", "integrity": "sha512-YNlnKRWF2sVojTpIyzwou9XoTNbzbzONwRhOoniEioF1AtaitTvVZblaQRrAzChWQ1bLYyYSWzM18y4WwgzJ+A==", + "dev": true, "license": "Apache-2.0", "dependencies": { "tslib": "^2.4.0" } }, + "node_modules/@swc/jest": { + "version": "0.2.36", + "resolved": "https://registry.npmjs.org/@swc/jest/-/jest-0.2.36.tgz", + "integrity": "sha512-8X80dp81ugxs4a11z1ka43FPhP+/e+mJNXJSxiNYk8gIX/jPBtY4gQTrKu/KIoco8bzKuPI5lUxjfLiGsfvnlw==", + "dev": true, + "license": "MIT", + "dependencies": { + "@jest/create-cache-key-function": "^29.7.0", + "@swc/counter": "^0.1.3", + "jsonc-parser": "^3.2.0" + }, + "engines": { + "npm": ">= 7.0.0" + }, + "peerDependencies": { + "@swc/core": "*" + } + }, "node_modules/@swc/types": { "version": "0.1.9", "resolved": "https://registry.npmjs.org/@swc/types/-/types-0.1.9.tgz", diff --git a/package.json b/package.json index 47da02aa..880b7200 100644 --- a/package.json +++ b/package.json @@ -19,7 +19,6 @@ "@nx/devkit": "19.4.3", "@octokit/openapi-types": "22.1.0", "@renovate/pep440": "1.0.0", - "@swc/helpers": "0.5.11", "chalk": "4.1.2", "ci-info": "4.0.0", "clipanion": "4.0.0-rc.3", @@ -48,6 +47,8 @@ "@swc-node/register": "1.9.2", "@swc/cli": "0.3.12", "@swc/core": "1.5.7", + "@swc/helpers": "~0.5.11", + "@swc/jest": "~0.2.36", "@types/jest": "29.5.6", "@types/node": "18.19.31", "@types/semver": "7.5.8", diff --git a/packages/nx-set-shas/.swcrc b/packages/nx-set-shas/.swcrc new file mode 100644 index 00000000..42425858 --- /dev/null +++ b/packages/nx-set-shas/.swcrc @@ -0,0 +1,29 @@ +{ + "jsc": { + "target": "es2021", + "parser": { + "syntax": "typescript", + "decorators": true, + "dynamicImport": true + }, + "transform": { + "decoratorMetadata": true, + "legacyDecorator": true + }, + "keepClassNames": true, + "externalHelpers": true, + "loose": true + }, + "module": { + "type": "commonjs" + }, + "sourceMaps": true, + "exclude": [ + "jest.config.ts", + ".*\\.spec.tsx?$", + ".*\\.test.tsx?$", + "./src/jest-setup.ts$", + "./**/jest-setup.ts$", + ".*.js$" + ] +} diff --git a/packages/nx-set-shas/jest.config.ts b/packages/nx-set-shas/jest.config.ts index fe974d58..fd32bb3b 100644 --- a/packages/nx-set-shas/jest.config.ts +++ b/packages/nx-set-shas/jest.config.ts @@ -1,10 +1,27 @@ /* eslint-disable */ +import { readFileSync } from 'fs'; + +// Reading the SWC compilation config and remove the "exclude" +// for the test files to be compiled by SWC +const { exclude: _, ...swcJestConfig } = JSON.parse(readFileSync(`${__dirname}/.swcrc`, 'utf-8')); + +// disable .swcrc look-up by SWC core because we're passing in swcJestConfig ourselves. +// If we do not disable this, SWC Core will read .swcrc and won't transform our test files due to "exclude" +if (swcJestConfig.swcrc === undefined) { + swcJestConfig.swcrc = false; +} + +// Uncomment if using global setup/teardown files being transformed via swc +// https://nx.dev/nx-api/jest/documents/overview#global-setupteardown-with-nx-libraries +// jest needs EsModule Interop to find the default exported setup/teardown functions +// swcJestConfig.module.noInterop = false; + export default { displayName: 'nx-set-shas', preset: '../../jest.preset.js', testEnvironment: 'node', transform: { - '^.+\\.[tj]s$': ['ts-jest', { tsconfig: '/tsconfig.spec.json' }], + '^.+\\.[tj]s$': ['@swc/jest', swcJestConfig], }, moduleFileExtensions: ['ts', 'js', 'html'], coverageDirectory: '../../coverage/packages/nx-set-shas', diff --git a/packages/nx-set-shas/package.json b/packages/nx-set-shas/package.json index b5d09c7a..0248a0d0 100644 --- a/packages/nx-set-shas/package.json +++ b/packages/nx-set-shas/package.json @@ -9,11 +9,11 @@ }, "dependencies": { "@nx-tools/core": "6.0.1", - "clipanion": "^4.0.0-rc.3", "chalk": "^4.1.2", - "semver": "^7.6.0" + "clipanion": "^4.0.0-rc.3", + "semver": "^7.6.2" }, "peerDependencies": { - "tslib": "^2.5.0" + "@swc/helpers": "~0.5.11" } } diff --git a/packages/nx-set-shas/project.json b/packages/nx-set-shas/project.json index 0070fcfa..ff01266b 100644 --- a/packages/nx-set-shas/project.json +++ b/packages/nx-set-shas/project.json @@ -14,7 +14,7 @@ "tags": ["type:cli", "scope:nx-set-shas"], "targets": { "build": { - "executor": "@nx/js:tsc", + "executor": "@nx/js:swc", "outputs": ["{options.outputPath}"], "options": { "outputPath": "dist/packages/nx-set-shas", diff --git a/packages/nx-set-shas/src/index.ts b/packages/nx-set-shas/src/index.ts index 65b2fb17..6aec109d 100644 --- a/packages/nx-set-shas/src/index.ts +++ b/packages/nx-set-shas/src/index.ts @@ -1,4 +1,5 @@ #!/usr/bin/env node + import { logger } from '@nx-tools/core'; import { Builtins, Cli } from 'clipanion'; import { version } from '../package.json';