From f1c342e05eb84254c9d84a425b4f0da1249fcef3 Mon Sep 17 00:00:00 2001 From: James Date: Tue, 10 Jan 2023 11:48:40 -0500 Subject: [PATCH] feat: requires ts-node to start a project for any config that uses ts or jsx --- nodemon.json | 2 +- package.json | 3 +-- src/config/load.ts | 19 ------------------ test/dev.js | 36 ----------------------------------- test/{devServer.ts => dev.ts} | 22 ++++++++++++++++++++- tsconfig.json | 3 +++ yarn.lock | 20 +++---------------- 7 files changed, 29 insertions(+), 76 deletions(-) delete mode 100644 test/dev.js rename test/{devServer.ts => dev.ts} (62%) diff --git a/nodemon.json b/nodemon.json index 75486eb21..e88a0eb69 100644 --- a/nodemon.json +++ b/nodemon.json @@ -12,5 +12,5 @@ "test/" ], "ext": "ts,js,json", - "exec": "node ./test/dev.js" + "exec": "ts-node ./test/dev.ts" } diff --git a/package.json b/package.json index dd29aed36..b986a7806 100644 --- a/package.json +++ b/package.json @@ -88,7 +88,6 @@ "@faceless-ui/window-info": "^2.0.2", "@monaco-editor/react": "^4.4.6", "@swc/core": "^1.3.24", - "@swc/register": "^0.1.10", "body-parser": "^1.19.0", "bson-objectid": "^2.0.1", "compression": "^1.7.4", @@ -181,6 +180,7 @@ "swc-minify-webpack-plugin": "^1.0.1", "terser-webpack-plugin": "^5.0.3", "ts-essentials": "^7.0.1", + "ts-node": "^10.9.1", "url-loader": "^4.1.1", "use-context-selector": "^1.4.1", "uuid": "^8.1.0", @@ -284,7 +284,6 @@ "shelljs": "^0.8.5", "slash": "^3.0.0", "start-server-and-test": "^1.14.0", - "ts-node": "^10.9.1", "typescript": "^4.1.2" }, "files": [ diff --git a/src/config/load.ts b/src/config/load.ts index b5e62595c..c55ba9771 100644 --- a/src/config/load.ts +++ b/src/config/load.ts @@ -1,7 +1,6 @@ /* eslint-disable import/no-dynamic-require */ /* eslint-disable global-require */ // eslint-disable-next-line import/no-extraneous-dependencies -import swcRegister from '@swc/register'; import path from 'path'; import pino from 'pino'; import Logger from '../utilities/logger'; @@ -15,24 +14,6 @@ const loadConfig = (logger?: pino.Logger): SanitizedConfig => { const configPath = findConfig(); - // eslint-disable-next-line @typescript-eslint/ban-ts-comment - // @ts-ignore - swcRegister({ - sourceMaps: 'inline', - jsc: { - parser: { - syntax: 'typescript', - tsx: true, - }, - }, - ignore: [ - /node_modules[\\/](?!.pnpm[\\/].*[\\/]node_modules[\\/])(?!payload[\\/]dist[\\/]admin|payload[\\/]components).*/, - ], - module: { - type: 'commonjs', - }, - }); - clientFiles.forEach((ext) => { require.extensions[ext] = () => null; }); diff --git a/test/dev.js b/test/dev.js deleted file mode 100644 index e45fa08cc..000000000 --- a/test/dev.js +++ /dev/null @@ -1,36 +0,0 @@ -const fs = require('fs'); -const path = require('path'); -const swcRegister = require('@swc/register'); - -const [testSuiteDir] = process.argv.slice(2); - -if (!testSuiteDir) { - console.error('ERROR: You must provide an argument for "testSuiteDir"'); - process.exit(1); -} - -const configPath = path.resolve(__dirname, testSuiteDir, 'config.ts'); - -if (!fs.existsSync(configPath)) { - console.error('ERROR: You must pass a valid directory under test/ that contains a config.ts'); - process.exit(1); -} - -process.env.PAYLOAD_CONFIG_PATH = configPath; - -process.env.PAYLOAD_DROP_DATABASE = 'true'; - -swcRegister({ - sourceMaps: 'inline', - jsc: { - parser: { - syntax: 'typescript', - tsx: true, - }, - }, - module: { - type: 'commonjs', - }, -}); - -require('./devServer'); diff --git a/test/devServer.ts b/test/dev.ts similarity index 62% rename from test/devServer.ts rename to test/dev.ts index 49138309b..2e7bd06c6 100644 --- a/test/devServer.ts +++ b/test/dev.ts @@ -1,9 +1,29 @@ - +import fs from 'fs'; +import path from 'path'; import express from 'express'; import { v4 as uuid } from 'uuid'; import payload from '../src'; +const [testSuiteDir] = process.argv.slice(2); + +if (!testSuiteDir) { + console.error('ERROR: You must provide an argument for "testSuiteDir"'); + process.exit(1); +} + +const configPath = path.resolve(__dirname, testSuiteDir, 'config.ts'); + +if (!fs.existsSync(configPath)) { + console.error('ERROR: You must pass a valid directory under test/ that contains a config.ts'); + process.exit(1); +} + +process.env.PAYLOAD_CONFIG_PATH = configPath; + +process.env.PAYLOAD_DROP_DATABASE = 'true'; + const expressApp = express(); + const init = async () => { await payload.init({ secret: uuid(), diff --git a/tsconfig.json b/tsconfig.json index 977258503..c24c245b3 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -30,6 +30,9 @@ "skipLibCheck": true, /* Skip type checking of declaration files. */ "forceConsistentCasingInFileNames": true, /* Disallow inconsistently-cased references to the same file. */ }, + "ts-node": { + "swc": true, + }, "include": [ "src/" ], diff --git a/yarn.lock b/yarn.lock index ca47c7084..3cbbeca23 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1950,15 +1950,6 @@ "@jest/create-cache-key-function" "^27.4.2" jsonc-parser "^3.2.0" -"@swc/register@^0.1.10": - version "0.1.10" - resolved "https://registry.yarnpkg.com/@swc/register/-/register-0.1.10.tgz#74a20b7559669e03479b05e9e5c6d1524d4d92a2" - integrity sha512-6STwH/q4dc3pitXLVkV7sP0Hiy+zBsU2wOF1aXpXR95pnH3RYHKIsDC+gvesfyB7jxNT9OOZgcqOp9RPxVTx9A== - dependencies: - lodash.clonedeep "^4.5.0" - pirates "^4.0.1" - source-map-support "^0.5.13" - "@szmarczak/http-timer@^5.0.1": version "5.0.1" resolved "https://registry.yarnpkg.com/@szmarczak/http-timer/-/http-timer-5.0.1.tgz#c7c1bf1141cdd4751b0399c8fc7b8b664cd5be3a" @@ -8079,11 +8070,6 @@ locate-path@^5.0.0: dependencies: p-locate "^4.1.0" -lodash.clonedeep@^4.5.0: - version "4.5.0" - resolved "https://registry.yarnpkg.com/lodash.clonedeep/-/lodash.clonedeep-4.5.0.tgz#e23f3f9c4f8fbdde872529c1071857a086e5ccef" - integrity sha512-H5ZhCF25riFd9uB5UCkVKo61m3S/xZk1x4wA6yp/L3RFP6Z/eHH1ymQcGLo7J3GMPfm0V/7m1tryHuGVxpqEBQ== - lodash.get@^4.4.2: version "4.4.2" resolved "https://registry.yarnpkg.com/lodash.get/-/lodash.get-4.4.2.tgz#2d177f652fa31e939b4438d5341499dfa3825e99" @@ -9353,7 +9339,7 @@ pino@^6.4.1: quick-format-unescaped "^4.0.3" sonic-boom "^1.0.2" -pirates@^4.0.1, pirates@^4.0.4: +pirates@^4.0.4: version "4.0.5" resolved "https://registry.yarnpkg.com/pirates/-/pirates-4.0.5.tgz#feec352ea5c3268fb23a37c702ab1699f35a5f3b" integrity sha512-8V9+HQPupnaXMA23c5hvl69zXvTwTzyAYasnkb0Tts4XvO4CliqONMOnvlq26rkhLC3nWDFBJf73LU1e1VZLaQ== @@ -11159,7 +11145,7 @@ source-map-support@0.5.13: buffer-from "^1.0.0" source-map "^0.6.0" -source-map-support@^0.5.13, source-map-support@~0.5.20: +source-map-support@~0.5.20: version "0.5.21" resolved "https://registry.yarnpkg.com/source-map-support/-/source-map-support-0.5.21.tgz#04fe7c7f9e1ed2d662233c28cb2b35b9f63f6e4f" integrity sha512-uBHU3L3czsIyYXKX88fdrGovxdSCoTGDRZ6SYXtSRxLZUzHg5P/66Ht6uoUlHu9EZod+inXhKo3qQgwXUT/y1w== @@ -11773,7 +11759,7 @@ ts-essentials@^7.0.1: ts-node@^10.9.1: version "10.9.1" - resolved "https://registry.yarnpkg.com/ts-node/-/ts-node-10.9.1.tgz#e73de9102958af9e1f0b168a6ff320e25adcff4b" + resolved "https://registry.npmjs.org/ts-node/-/ts-node-10.9.1.tgz#e73de9102958af9e1f0b168a6ff320e25adcff4b" integrity sha512-NtVysVPkxxrwFGUUxGYhfux8k78pQB3JqYBXlLRZgdGUqTO5wU/UyHop5p70iEbGhB7q5KmiZiU0Y3KlJrScEw== dependencies: "@cspotcode/source-map-support" "^0.8.0"