diff --git a/package.json b/package.json index aa9a15971ad3e..34cc627dfeb3f 100644 --- a/package.json +++ b/package.json @@ -90,6 +90,7 @@ "@storybook/core": "~6.4.12", "@storybook/react": "~6.4.12", "@svgr/webpack": "^6.1.2", + "@swc/core": "^1.2.146", "@swc-node/register": "^1.4.2", "@testing-library/react": "11.2.6", "@testing-library/react-hooks": "7.0.1", @@ -258,12 +259,6 @@ "yargs-parser": "20.0.0", "zone.js": "~0.11.4" }, - "optionalDependencies": { - "@swc/core-linux-arm64-gnu": "^1.2.136", - "@swc/core-linux-arm64-musl": "^1.2.136", - "@swc/core-linux-x64-gnu": "^1.2.136", - "@swc/core-linux-x64-musl": "^1.2.136" - }, "author": "Victor Savkin", "license": "MIT", "config": { diff --git a/packages/eslint-plugin-nx/package.json b/packages/eslint-plugin-nx/package.json index b2ecd505ea2ac..7aad6286cd8b2 100644 --- a/packages/eslint-plugin-nx/package.json +++ b/packages/eslint-plugin-nx/package.json @@ -34,16 +34,8 @@ "dependencies": { "@nrwl/devkit": "*", "@nrwl/workspace": "*", - "@swc-node/register": "^1.4.2", "@typescript-eslint/experimental-utils": "~5.10.0", "chalk": "4.1.0", - "confusing-browser-globals": "^1.0.9", - "tsconfig-paths": "^3.9.0" - }, - "optionalDependencies": { - "@swc/core-linux-x64-musl": "^1.2.136", - "@swc/core-linux-x64-gnu": "^1.2.136", - "@swc/core-linux-arm64-gnu": "^1.2.136", - "@swc/core-linux-arm64-musl": "^1.2.136" + "confusing-browser-globals": "^1.0.9" } } diff --git a/packages/eslint-plugin-nx/src/resolve-workspace-rules.ts b/packages/eslint-plugin-nx/src/resolve-workspace-rules.ts index 127fda07d5843..a55330aa7fa09 100644 --- a/packages/eslint-plugin-nx/src/resolve-workspace-rules.ts +++ b/packages/eslint-plugin-nx/src/resolve-workspace-rules.ts @@ -1,47 +1,17 @@ import type { TSESLint } from '@typescript-eslint/experimental-utils'; import { existsSync } from 'fs'; -import { join } from 'path'; import { WORKSPACE_PLUGIN_DIR, WORKSPACE_RULE_NAMESPACE } from './constants'; -import { readDefaultTsConfig } from '@swc-node/register/read-default-tsconfig'; -import { register } from '@swc-node/register/register'; +import { registerTsProject } from '@nrwl/tao/src/utils/register'; type ESLintRules = Record>; -/** - * Optionally, if ts-node and tsconfig-paths are available in the current workspace, apply the require - * register hooks so that .ts files can be used for writing workspace lint rules. - * - * If ts-node and tsconfig-paths are not available, the user can still provide an index.js file in - * tools/eslint-rules and write their rules in JavaScript and the fundamentals will still work (but - * workspace path mapping will not, for example). - */ -function registerTSWorkspaceLint() { - try { - register(readDefaultTsConfig(join(WORKSPACE_PLUGIN_DIR, 'tsconfig.json'))); - - const tsconfigPaths = require('tsconfig-paths'); - - // Load the tsconfig from tools/eslint-rules/tsconfig.json - const tsConfigResult = tsconfigPaths.loadConfig(WORKSPACE_PLUGIN_DIR); - - /** - * Register the custom workspace path mappings with node so that workspace libraries - * can be imported and used within custom workspace lint rules. - */ - return tsconfigPaths.register({ - baseUrl: tsConfigResult.absoluteBaseUrl, - paths: tsConfigResult.paths, - }); - } catch (err) {} -} - export const workspaceRules = ((): ESLintRules => { // If `tools/eslint-rules` folder doesn't exist, there is no point trying to register and load it if (!existsSync(WORKSPACE_PLUGIN_DIR)) { return {}; } // Register `tools/eslint-rules` for TS transpilation - const registrationCleanup = registerTSWorkspaceLint(); + const registrationCleanup = registerTsProject(WORKSPACE_PLUGIN_DIR); try { /** * Currently we only support applying the rules from the user's workspace plugin object diff --git a/packages/tao/package.json b/packages/tao/package.json index c5960295581f1..3798c71a5888d 100644 --- a/packages/tao/package.json +++ b/packages/tao/package.json @@ -30,6 +30,8 @@ }, "homepage": "https://nx.dev", "dependencies": { + "@swc/core": "^1.2.146", + "@swc-node/register": "^1.4.2", "chalk": "4.1.0", "enquirer": "~2.3.6", "fast-glob": "3.2.7", @@ -41,6 +43,7 @@ "semver": "7.3.4", "tmp": "~0.2.1", "tslib": "^2.3.0", + "tsconfig-paths": "^3.9.0", "yargs-parser": "20.0.0" } } diff --git a/packages/tao/src/utils/register.ts b/packages/tao/src/utils/register.ts new file mode 100644 index 0000000000000..4c7d1895b868b --- /dev/null +++ b/packages/tao/src/utils/register.ts @@ -0,0 +1,35 @@ +import { readDefaultTsConfig } from '@swc-node/register/read-default-tsconfig'; +import { register } from '@swc-node/register/register'; +import { join } from 'path'; + +/** + * Optionally, if swc-node and tsconfig-paths are available in the current workspace, apply the require + * register hooks so that .ts files can be used for writing custom workspace projects. + * + * If ts-node and tsconfig-paths are not available, the user can still provide an index.js file in + * the root of their project and the fundamentals will still work (but + * workspace path mapping will not, for example). + */ +export const registerTsProject = ( + path: string, + configFilename = 'tsconfig.json' +) => { + try { + const tsConfig = readDefaultTsConfig(join(path, configFilename)); + register(tsConfig); + + /** + * Load the ts config from the source project + */ + const tsconfigPaths = require('tsconfig-paths'); + const tsConfigResult = tsconfigPaths.loadConfig(path); + /** + * Register the custom workspace path mappings with node so that workspace libraries + * can be imported and used within project + */ + return tsconfigPaths.register({ + baseUrl: tsConfigResult.absoluteBaseUrl, + paths: tsConfigResult.paths, + }); + } catch (err) {} +}; diff --git a/yarn.lock b/yarn.lock index 5f7b72e386ca2..45769845189bf 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5496,36 +5496,71 @@ resolved "https://registry.yarnpkg.com/@swc/core-android-arm-eabi/-/core-android-arm-eabi-1.2.133.tgz#dea04365897889c6f827ceb544ea241c90f02709" integrity sha512-S6gc8Z1zhkDmMRwjeGp5Wf8zE+Vwc5m3weSltUTxbO27r48X6A8R2egM48ci/muPTPA6mOWQTViTFcq/hEgV2w== +"@swc/core-android-arm-eabi@1.2.146": + version "1.2.146" + resolved "https://registry.yarnpkg.com/@swc/core-android-arm-eabi/-/core-android-arm-eabi-1.2.146.tgz#027c9b0c57377ce6cf4c7806ba07acf156e70d3a" + integrity sha512-vRlxDksEDdprqfj9VACYUGyCJr/tYLetNjhjel46qmKoXU5uAib1WLWWgMB1Ur+oh8eCSTN8cnOblOziqfC1Rw== + "@swc/core-android-arm64@1.2.133": version "1.2.133" resolved "https://registry.yarnpkg.com/@swc/core-android-arm64/-/core-android-arm64-1.2.133.tgz#9467327193885692d6b9204599bcb16863e3ccab" integrity sha512-rlsJ+UCk6QOUVde2l4yeM32R04KbnOM6a2WBw43f5IA8M8PDlWdRNHFE3jiwCIwBoG6MJ+EJE2PPmjxr3iSWvw== +"@swc/core-android-arm64@1.2.146": + version "1.2.146" + resolved "https://registry.yarnpkg.com/@swc/core-android-arm64/-/core-android-arm64-1.2.146.tgz#e906088244bab3672ef4c40bd0631d2a09ab51fd" + integrity sha512-YoJygRvjZ6IXvWstYZHGThEj1aWshzoMohX0i6WH5NIZhkzeF0UhRu/IZoS9VcQsd0WtDEMQe0G0wcrd/FToNg== + "@swc/core-darwin-arm64@1.2.133": version "1.2.133" resolved "https://registry.yarnpkg.com/@swc/core-darwin-arm64/-/core-darwin-arm64-1.2.133.tgz#95e6d46a8406c4b09e96eec4a3f0bad270285744" integrity sha512-COktqzeii453+JCGwgIM8vs4y4bgbIzY2lvSEYQmxZRVMAkqQVviLqG4cjm9tYHrW0o+9zpw+XTgpdPpkg32Yg== +"@swc/core-darwin-arm64@1.2.146": + version "1.2.146" + resolved "https://registry.yarnpkg.com/@swc/core-darwin-arm64/-/core-darwin-arm64-1.2.146.tgz#e47a8f5c1b18278c1005007121553a3d01d15622" + integrity sha512-ftAyhczQHSUQo1Mox/VyZ3YL9KtG0LgOFUUUuLD3Pb9zKQB20Jc/Dfnh/bFktemVG8XiH0rOyR9yEI2EANHuEA== + "@swc/core-darwin-x64@1.2.133": version "1.2.133" resolved "https://registry.yarnpkg.com/@swc/core-darwin-x64/-/core-darwin-x64-1.2.133.tgz#d40999cb465a160c1226fef42df31c7be1ed4999" integrity sha512-H5Hk+qWotdgVQOuQZdSMmIo4KUGxJjfVVBBbKe+TG1Vqyo5SQderc9TUZH8UzMP/tlX83Nzin0FHB+Ui9UhYqA== +"@swc/core-darwin-x64@1.2.146": + version "1.2.146" + resolved "https://registry.yarnpkg.com/@swc/core-darwin-x64/-/core-darwin-x64-1.2.146.tgz#5e9a2d9fe1049ec8cdaec265b73781eb08579365" + integrity sha512-mYRN/WTS7TfYt3jqJYghcrpAW7zkpjdeEx9Rot8rmUEmk97luh9Bcwqafzjb9ndoG1mAiaTQcqvs/QqT2efS5Q== + "@swc/core-freebsd-x64@1.2.133": version "1.2.133" resolved "https://registry.yarnpkg.com/@swc/core-freebsd-x64/-/core-freebsd-x64-1.2.133.tgz#0968766e4ff69509ae347e4fed3accb1f1e97c53" integrity sha512-eFYkZLyAghY90w7CfwHsQ7/doJ46QSlmMGA9qR9NEuPt9MthM84ZXE6d20BvOid0zeib2o6HdFzfaAkS09/hvA== +"@swc/core-freebsd-x64@1.2.146": + version "1.2.146" + resolved "https://registry.yarnpkg.com/@swc/core-freebsd-x64/-/core-freebsd-x64-1.2.146.tgz#6bda670ae5abb05abecb51d832950b3c159289d1" + integrity sha512-eYU5g7p/dY98+hvg3VJtwiX+btRWnq+WO4y4M+X1nguqghvuTv6jtVLeHDNr8FEhc+FMSJPYKO321ZVa0xCKXw== + "@swc/core-linux-arm-gnueabihf@1.2.133": version "1.2.133" resolved "https://registry.yarnpkg.com/@swc/core-linux-arm-gnueabihf/-/core-linux-arm-gnueabihf-1.2.133.tgz#fcbefd1783c8fbde44d965ec0fb051387c3c92a9" integrity sha512-oB9L0Xs6cfOYUr7Qc8tpPd3IpY3dXIaJZ/OZQqFhIQFzeMZVApaLBeyfX+gwH8d8wgceuPj4HeyZE+IWw2GTJQ== +"@swc/core-linux-arm-gnueabihf@1.2.146": + version "1.2.146" + resolved "https://registry.yarnpkg.com/@swc/core-linux-arm-gnueabihf/-/core-linux-arm-gnueabihf-1.2.146.tgz#f37f6876cfd42bb58037f7c3b2dd13b58f1cf40d" + integrity sha512-ahKwlP9b41HUlwY+0eRJjgG4yJZN+uT16iBB2X7VedipmRO0aOOaP8xLReDjn4Z13DL14iAPC6Jnxiaw5rl8LQ== + "@swc/core-linux-arm64-gnu@1.2.133": version "1.2.133" resolved "https://registry.yarnpkg.com/@swc/core-linux-arm64-gnu/-/core-linux-arm64-gnu-1.2.133.tgz#2d2986824aaf1dd58c4b4e173d6186b7e2073d54" integrity sha512-SF0Yviv+9L1ELsn578/TJd44rIhqbGGAD+AgpyJB8YGoFTAFUTnoAhFYNEPOEfbf/IQyWcyHk3vAZ7a2VPRIFg== +"@swc/core-linux-arm64-gnu@1.2.146": + version "1.2.146" + resolved "https://registry.yarnpkg.com/@swc/core-linux-arm64-gnu/-/core-linux-arm64-gnu-1.2.146.tgz#9daed25cbcc3fcfbf792fadc26b0d13a1bd8a130" + integrity sha512-S/0EJI8BWBQtsyIuYwVg+Gq03NlGl/xWOJgwLJss5+DawvxK8YZFteczw7M/bN/E5D2TqZRyybLM6baQozgDAg== + "@swc/core-linux-arm64-gnu@^1.2.136": version "1.2.136" resolved "https://registry.yarnpkg.com/@swc/core-linux-arm64-gnu/-/core-linux-arm64-gnu-1.2.136.tgz#111a008e54d1e38b33a0d3d3134309a002f6a3b7" @@ -5536,6 +5571,11 @@ resolved "https://registry.yarnpkg.com/@swc/core-linux-arm64-musl/-/core-linux-arm64-musl-1.2.133.tgz#9daae6e86b9c692aecdaa6109721a5ff00d114ad" integrity sha512-tZiqwz7dTOxnGMwnYguULKl6gNom6CQWXoUyoliksaZA6+uNALO1/PNh/ctzuDbu2Agj4ltsmoevhZlrzC3geA== +"@swc/core-linux-arm64-musl@1.2.146": + version "1.2.146" + resolved "https://registry.yarnpkg.com/@swc/core-linux-arm64-musl/-/core-linux-arm64-musl-1.2.146.tgz#af5bdc23160fbb9db49ea1f05580000baabde063" + integrity sha512-tOHcanuqgniMwUWMwjA+zr/hZyVn931l8DiIi3Mthyplp/PDY68PVAUJ8miJd4C5XDPcYfPOe5kRyXsFrdZzhw== + "@swc/core-linux-arm64-musl@^1.2.136": version "1.2.136" resolved "https://registry.yarnpkg.com/@swc/core-linux-arm64-musl/-/core-linux-arm64-musl-1.2.136.tgz#86d3a207ba519ce38410bb0f896baa6279de4051" @@ -5546,6 +5586,11 @@ resolved "https://registry.yarnpkg.com/@swc/core-linux-x64-gnu/-/core-linux-x64-gnu-1.2.133.tgz#77439a67f2e39125b2f6c5c62d70accaf5140323" integrity sha512-xXx+/x9y803chUtOqsETvZjimCEiFNcYobsV4wDzlO/E9njrDhmteGcHOv5C6cGSfP6H8tG+hL1JlqJQm+hPSQ== +"@swc/core-linux-x64-gnu@1.2.146": + version "1.2.146" + resolved "https://registry.yarnpkg.com/@swc/core-linux-x64-gnu/-/core-linux-x64-gnu-1.2.146.tgz#aeef122f0b313fb95438e209f22697ddb3da5c7d" + integrity sha512-w9jHnFe1XLYfQYWkaJwKgmtb/HKsgyFy0sCQpVjgDq/+ds8PPyACthDINpiEMsAOFN+IfE59HDn4A2gN3qyVgg== + "@swc/core-linux-x64-gnu@^1.2.136": version "1.2.136" resolved "https://registry.yarnpkg.com/@swc/core-linux-x64-gnu/-/core-linux-x64-gnu-1.2.136.tgz#91a44b439743e59b1e1d649a87032db44d2214d3" @@ -5556,6 +5601,11 @@ resolved "https://registry.yarnpkg.com/@swc/core-linux-x64-musl/-/core-linux-x64-musl-1.2.133.tgz#f37122c608d9392a3dbda4189e1d68db46f49614" integrity sha512-LnLY5MnwG/L7U+FC/k5LU4K7h+kz5/fo8DC507BncSZj5LLxT9ohhCxO+iUp7qKGw+UQFgSUgUinh1I8FfV6cQ== +"@swc/core-linux-x64-musl@1.2.146": + version "1.2.146" + resolved "https://registry.yarnpkg.com/@swc/core-linux-x64-musl/-/core-linux-x64-musl-1.2.146.tgz#d146fd167e9d84a08637a9e1d535b04f2204bd99" + integrity sha512-iwKiHvV8p48/82+eJRCy/WcnAZBOFr2ZJ5VLtRuV+sz0mkWjoimnLZ8SEshoru9PVoKF7hfG7AMqKaVOUjSJFg== + "@swc/core-linux-x64-musl@^1.2.136": version "1.2.136" resolved "https://registry.yarnpkg.com/@swc/core-linux-x64-musl/-/core-linux-x64-musl-1.2.136.tgz#0bdde1359245642f6126d6f62e8abe0a1c791f0a" @@ -5566,16 +5616,31 @@ resolved "https://registry.yarnpkg.com/@swc/core-win32-arm64-msvc/-/core-win32-arm64-msvc-1.2.133.tgz#322ea6234182005a81a2b3e64d3e35273057bd8c" integrity sha512-Fk4D8v56TOhoP5lRFSoZqWXt8enCdHGbZsSIdz7DSjQyS/VeePXdoZI8vmWUcuy2OSquQ4hpS2o1v3wVSREWiw== +"@swc/core-win32-arm64-msvc@1.2.146": + version "1.2.146" + resolved "https://registry.yarnpkg.com/@swc/core-win32-arm64-msvc/-/core-win32-arm64-msvc-1.2.146.tgz#23b52c4fdcf1395861eb915924285b7857c3db68" + integrity sha512-n21riIEGTPim19Y0mrBIDVZfOrYdfd2W8QEgbiG/f+kcOlWckvyh9ZKexd6D8QpHe73C4lOX1RrmH3DgnPGhqA== + "@swc/core-win32-ia32-msvc@1.2.133": version "1.2.133" resolved "https://registry.yarnpkg.com/@swc/core-win32-ia32-msvc/-/core-win32-ia32-msvc-1.2.133.tgz#b9766f17821ce3ae7010577174df2549f92a8a07" integrity sha512-Sf9UmXSPFr7308OSDfIIU0iLRfzilWlnVfVzUfWLd02Z9t5awBxNYCAZrXxny4FUvTDK9qL+/uY378bFH6tYiw== +"@swc/core-win32-ia32-msvc@1.2.146": + version "1.2.146" + resolved "https://registry.yarnpkg.com/@swc/core-win32-ia32-msvc/-/core-win32-ia32-msvc-1.2.146.tgz#3e56db016661cf877b8ae39056fadbb14ec17eef" + integrity sha512-5b99VzxvTqTQCZDmpKrGevUc9SK0QBiGZG4Oeh5CnSJyx8SZU0A3R7rbMoSR5/raP9OA/0ZvlXefUDXIsKNadA== + "@swc/core-win32-x64-msvc@1.2.133": version "1.2.133" resolved "https://registry.yarnpkg.com/@swc/core-win32-x64-msvc/-/core-win32-x64-msvc-1.2.133.tgz#5afc09724bac622e6f40ce6cd5e901e1458aad98" integrity sha512-nXZJihzwUjzzF78ipPp+uUWmLQtbFzuR5eADNk1MsnHgWflKaL5OXNVz5c8+qyTl5/c3/W1b4GSevFOfEuApxw== +"@swc/core-win32-x64-msvc@1.2.146": + version "1.2.146" + resolved "https://registry.yarnpkg.com/@swc/core-win32-x64-msvc/-/core-win32-x64-msvc-1.2.146.tgz#e9010b06fbfebdc745d2dd324b752ddd4f685bc9" + integrity sha512-P45vAh0hR9dISIceSv6MkypjT0WduLWB4U8LPoCneeAw7mA1U7liS0Uu1PeiafxQVMWg8SNyIJFDcSg/haLJgg== + "@swc/core@^1.2.119": version "1.2.133" resolved "https://registry.yarnpkg.com/@swc/core/-/core-1.2.133.tgz#2d0654b2135ea822e2933c02e150563165bdefff" @@ -5595,6 +5660,25 @@ "@swc/core-win32-ia32-msvc" "1.2.133" "@swc/core-win32-x64-msvc" "1.2.133" +"@swc/core@^1.2.146": + version "1.2.146" + resolved "https://registry.yarnpkg.com/@swc/core/-/core-1.2.146.tgz#dd86c65d101e1414f9d5a14a22c3541dd4dcfeef" + integrity sha512-axIapm2mReT45ILuYxwe0xEWqtITj3dyfDIGIgdC8Tx7ss5vpXvr22UbDSUTRIS+nypFy6hViIR1RhXE1hXnig== + optionalDependencies: + "@swc/core-android-arm-eabi" "1.2.146" + "@swc/core-android-arm64" "1.2.146" + "@swc/core-darwin-arm64" "1.2.146" + "@swc/core-darwin-x64" "1.2.146" + "@swc/core-freebsd-x64" "1.2.146" + "@swc/core-linux-arm-gnueabihf" "1.2.146" + "@swc/core-linux-arm64-gnu" "1.2.146" + "@swc/core-linux-arm64-musl" "1.2.146" + "@swc/core-linux-x64-gnu" "1.2.146" + "@swc/core-linux-x64-musl" "1.2.146" + "@swc/core-win32-arm64-msvc" "1.2.146" + "@swc/core-win32-ia32-msvc" "1.2.146" + "@swc/core-win32-x64-msvc" "1.2.146" + "@szmarczak/http-timer@^1.1.2": version "1.1.2" resolved "https://registry.npmjs.org/@szmarczak/http-timer/-/http-timer-1.1.2.tgz"