From 3eb914162859013ff8413e5a1790ad283ab5c427 Mon Sep 17 00:00:00 2001 From: Ola Okelola Date: Fri, 5 May 2023 14:38:58 -0700 Subject: [PATCH] swc again for parse typescript and custom graphql uses https://github.com/swc-project/swc-node fixes https://github.com/lolopinto/ent/issues/792 cannot use ts-node anymore because it doesn't provide an option for .swcrc https://github.com/TypeStrong/ts-node/issues/1856 TODO: depends on https://github.com/swc-project/swc/issues/7358 to actually be used TODO: remove swc-node in examples/simple TODO: move .swcrc write in generate_ts_code.go into central location --- examples/simple/package-lock.json | 154 +++++++++++++++++++-- examples/simple/package.json | 1 + internal/cmd/cmd.go | 77 ++++++++++- internal/graphql/generate_ts_code.go | 64 +++++---- internal/schema/input/parse_ts.go | 26 +--- internal/testingutils/compiler_options.go | 2 +- ts/package-lock.json | 160 ++++++++++++++++++++-- ts/package.json | 3 +- ts/src/scripts/custom_graphql.ts | 8 +- 9 files changed, 416 insertions(+), 79 deletions(-) diff --git a/examples/simple/package-lock.json b/examples/simple/package-lock.json index 3bf6c28df..9dc1f12b3 100644 --- a/examples/simple/package-lock.json +++ b/examples/simple/package-lock.json @@ -14,6 +14,7 @@ "@snowtop/ent-passport": "^0.1.0-alpha3", "@snowtop/ent-password": "^0.1.0-alpha1", "@snowtop/ent-phonenumber": "^0.1.0-alpha1", + "@swc-node/register": "^1.6.5", "@swc/core": "^1.3.56", "@types/express-session": "^1.17.3", "@types/graphql-upload": "^8.0.11", @@ -1274,6 +1275,81 @@ "uuid": "dist/bin/uuid" } }, + "node_modules/@swc-node/core": { + "version": "1.10.3", + "resolved": "https://registry.npmjs.org/@swc-node/core/-/core-1.10.3.tgz", + "integrity": "sha512-8rpv1DXzsQjN/C8ZXuaTSmJ4M/lRr6geUlbOQ861DLC+sKWcEEvxRjK9cXQ28GserHuEcFDA3wlF9rD1YD0x+Q==", + "engines": { + "node": ">= 10" + }, + "funding": { + "type": "github", + "url": "https://github.com/sponsors/Brooooooklyn" + }, + "peerDependencies": { + "@swc/core": ">= 1.3" + } + }, + "node_modules/@swc-node/register": { + "version": "1.6.5", + "resolved": "https://registry.npmjs.org/@swc-node/register/-/register-1.6.5.tgz", + "integrity": "sha512-yMxXlzthI0aMadYYKDhx7xvtjljB1qoD8Tv0djqSJ1ttTkoDxg6MhG5A5pIahiUT2neVrkWb9lCavoUwXAe/zQ==", + "dependencies": { + "@swc-node/core": "^1.10.3", + "@swc-node/sourcemap-support": "^0.3.0", + "colorette": "^2.0.19", + "debug": "^4.3.4", + "pirates": "^4.0.5", + "tslib": "^2.5.0" + }, + "funding": { + "type": "github", + "url": "https://github.com/sponsors/Brooooooklyn" + }, + "peerDependencies": { + "@swc/core": ">= 1.3", + "typescript": ">= 4.3" + } + }, + "node_modules/@swc-node/register/node_modules/debug": { + "version": "4.3.4", + "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.4.tgz", + "integrity": "sha512-PRWFHuSU3eDtQJPvnNY7Jcket1j0t5OuOsFzPPzsekD52Zl8qUfFIPEiswXqIvHWGVHOgX+7G/vCNNhehwxfkQ==", + "dependencies": { + "ms": "2.1.2" + }, + "engines": { + "node": ">=6.0" + }, + "peerDependenciesMeta": { + "supports-color": { + "optional": true + } + } + }, + "node_modules/@swc-node/register/node_modules/ms": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", + "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==" + }, + "node_modules/@swc-node/sourcemap-support": { + "version": "0.3.0", + "resolved": "https://registry.npmjs.org/@swc-node/sourcemap-support/-/sourcemap-support-0.3.0.tgz", + "integrity": "sha512-gqBJSmJMWomZFxlppaKea7NeAqFrDrrS0RMt24No92M3nJWcyI9YKGEQKl+EyJqZ5gh6w1s0cTklMHMzRwA1NA==", + "dependencies": { + "source-map-support": "^0.5.21", + "tslib": "^2.5.0" + } + }, + "node_modules/@swc-node/sourcemap-support/node_modules/source-map-support": { + "version": "0.5.21", + "resolved": "https://registry.npmjs.org/source-map-support/-/source-map-support-0.5.21.tgz", + "integrity": "sha512-uBHU3L3czsIyYXKX88fdrGovxdSCoTGDRZ6SYXtSRxLZUzHg5P/66Ht6uoUlHu9EZod+inXhKo3qQgwXUT/y1w==", + "dependencies": { + "buffer-from": "^1.0.0", + "source-map": "^0.6.0" + } + }, "node_modules/@swc/core": { "version": "1.3.56", "resolved": "https://registry.npmjs.org/@swc/core/-/core-1.3.56.tgz", @@ -2174,8 +2250,7 @@ "node_modules/buffer-from": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/buffer-from/-/buffer-from-1.1.2.tgz", - "integrity": "sha512-E+XQCRwSbaaiChtv6k6Dwgc+bx+Bs6vuKJHHl5kox/BaKbhiXzqQOwK4cO22yElGp2OCmjwVhT3HmxgyPGnJfQ==", - "dev": true + "integrity": "sha512-E+XQCRwSbaaiChtv6k6Dwgc+bx+Bs6vuKJHHl5kox/BaKbhiXzqQOwK4cO22yElGp2OCmjwVhT3HmxgyPGnJfQ==" }, "node_modules/buffer-writer": { "version": "2.0.0", @@ -2346,6 +2421,11 @@ "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==", "dev": true }, + "node_modules/colorette": { + "version": "2.0.20", + "resolved": "https://registry.npmjs.org/colorette/-/colorette-2.0.20.tgz", + "integrity": "sha512-IfEDxwoWIjkeXL1eXcDiow4UbKjhLdq6/EuSVR9GMN7KVH3r9gQ83e73hsz1Nd1T3ijd5xv1wcWRYO+D6kCI2w==" + }, "node_modules/combined-stream": { "version": "1.0.8", "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz", @@ -4951,7 +5031,6 @@ "version": "4.0.5", "resolved": "https://registry.npmjs.org/pirates/-/pirates-4.0.5.tgz", "integrity": "sha512-8V9+HQPupnaXMA23c5hvl69zXvTwTzyAYasnkb0Tts4XvO4CliqONMOnvlq26rkhLC3nWDFBJf73LU1e1VZLaQ==", - "dev": true, "engines": { "node": ">= 6" } @@ -5384,7 +5463,6 @@ "version": "0.6.1", "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz", "integrity": "sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==", - "dev": true, "engines": { "node": ">=0.10.0" } @@ -7114,6 +7192,60 @@ "libphonenumber-js": "^1.9.17" } }, + "@swc-node/core": { + "version": "1.10.3", + "resolved": "https://registry.npmjs.org/@swc-node/core/-/core-1.10.3.tgz", + "integrity": "sha512-8rpv1DXzsQjN/C8ZXuaTSmJ4M/lRr6geUlbOQ861DLC+sKWcEEvxRjK9cXQ28GserHuEcFDA3wlF9rD1YD0x+Q==", + "requires": {} + }, + "@swc-node/register": { + "version": "1.6.5", + "resolved": "https://registry.npmjs.org/@swc-node/register/-/register-1.6.5.tgz", + "integrity": "sha512-yMxXlzthI0aMadYYKDhx7xvtjljB1qoD8Tv0djqSJ1ttTkoDxg6MhG5A5pIahiUT2neVrkWb9lCavoUwXAe/zQ==", + "requires": { + "@swc-node/core": "^1.10.3", + "@swc-node/sourcemap-support": "^0.3.0", + "colorette": "^2.0.19", + "debug": "^4.3.4", + "pirates": "^4.0.5", + "tslib": "^2.5.0" + }, + "dependencies": { + "debug": { + "version": "4.3.4", + "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.4.tgz", + "integrity": "sha512-PRWFHuSU3eDtQJPvnNY7Jcket1j0t5OuOsFzPPzsekD52Zl8qUfFIPEiswXqIvHWGVHOgX+7G/vCNNhehwxfkQ==", + "requires": { + "ms": "2.1.2" + } + }, + "ms": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", + "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==" + } + } + }, + "@swc-node/sourcemap-support": { + "version": "0.3.0", + "resolved": "https://registry.npmjs.org/@swc-node/sourcemap-support/-/sourcemap-support-0.3.0.tgz", + "integrity": "sha512-gqBJSmJMWomZFxlppaKea7NeAqFrDrrS0RMt24No92M3nJWcyI9YKGEQKl+EyJqZ5gh6w1s0cTklMHMzRwA1NA==", + "requires": { + "source-map-support": "^0.5.21", + "tslib": "^2.5.0" + }, + "dependencies": { + "source-map-support": { + "version": "0.5.21", + "resolved": "https://registry.npmjs.org/source-map-support/-/source-map-support-0.5.21.tgz", + "integrity": "sha512-uBHU3L3czsIyYXKX88fdrGovxdSCoTGDRZ6SYXtSRxLZUzHg5P/66Ht6uoUlHu9EZod+inXhKo3qQgwXUT/y1w==", + "requires": { + "buffer-from": "^1.0.0", + "source-map": "^0.6.0" + } + } + } + }, "@swc/core": { "version": "1.3.56", "resolved": "https://registry.npmjs.org/@swc/core/-/core-1.3.56.tgz", @@ -7827,8 +7959,7 @@ "buffer-from": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/buffer-from/-/buffer-from-1.1.2.tgz", - "integrity": "sha512-E+XQCRwSbaaiChtv6k6Dwgc+bx+Bs6vuKJHHl5kox/BaKbhiXzqQOwK4cO22yElGp2OCmjwVhT3HmxgyPGnJfQ==", - "dev": true + "integrity": "sha512-E+XQCRwSbaaiChtv6k6Dwgc+bx+Bs6vuKJHHl5kox/BaKbhiXzqQOwK4cO22yElGp2OCmjwVhT3HmxgyPGnJfQ==" }, "buffer-writer": { "version": "2.0.0", @@ -7949,6 +8080,11 @@ "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==", "dev": true }, + "colorette": { + "version": "2.0.20", + "resolved": "https://registry.npmjs.org/colorette/-/colorette-2.0.20.tgz", + "integrity": "sha512-IfEDxwoWIjkeXL1eXcDiow4UbKjhLdq6/EuSVR9GMN7KVH3r9gQ83e73hsz1Nd1T3ijd5xv1wcWRYO+D6kCI2w==" + }, "combined-stream": { "version": "1.0.8", "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz", @@ -9925,8 +10061,7 @@ "pirates": { "version": "4.0.5", "resolved": "https://registry.npmjs.org/pirates/-/pirates-4.0.5.tgz", - "integrity": "sha512-8V9+HQPupnaXMA23c5hvl69zXvTwTzyAYasnkb0Tts4XvO4CliqONMOnvlq26rkhLC3nWDFBJf73LU1e1VZLaQ==", - "dev": true + "integrity": "sha512-8V9+HQPupnaXMA23c5hvl69zXvTwTzyAYasnkb0Tts4XvO4CliqONMOnvlq26rkhLC3nWDFBJf73LU1e1VZLaQ==" }, "pkg-dir": { "version": "4.2.0", @@ -10247,8 +10382,7 @@ "source-map": { "version": "0.6.1", "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz", - "integrity": "sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==", - "dev": true + "integrity": "sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==" }, "source-map-support": { "version": "0.5.13", diff --git a/examples/simple/package.json b/examples/simple/package.json index 7e8294b1d..0d2c40cd8 100644 --- a/examples/simple/package.json +++ b/examples/simple/package.json @@ -38,6 +38,7 @@ "@snowtop/ent-passport": "^0.1.0-alpha3", "@snowtop/ent-password": "^0.1.0-alpha1", "@snowtop/ent-phonenumber": "^0.1.0-alpha1", + "@swc-node/register": "^1.6.5", "@swc/core": "^1.3.56", "@types/express-session": "^1.17.3", "@types/graphql-upload": "^8.0.11", diff --git a/internal/cmd/cmd.go b/internal/cmd/cmd.go index fbb063a06..08df2cbe9 100644 --- a/internal/cmd/cmd.go +++ b/internal/cmd/cmd.go @@ -1,8 +1,10 @@ package cmd import ( + "os" "path/filepath" + "github.com/lolopinto/ent/internal/testingutils" "github.com/lolopinto/ent/internal/util" ) @@ -13,14 +15,83 @@ func GetTsconfigPaths() string { // initial args for ts-node-script // we need tsconfig.json referenced because of relative paths like src/ent/generated/types.ts func GetArgsForScript(rootPath string) []string { + return append( + getArgsForScriptBoth(rootPath), + "-r", + "@swc-node/register", + ) +} + +func GetArgsForScriptSwc(rootPath string) []string { + return append( + getArgsForScriptBoth(rootPath), + "-r", + GetTsconfigPaths(), + ) +} + +func getArgsForScriptBoth(rootPath string) []string { return []string{ - // this seems to let the errors pass through s opposed to giving compile error + // this seems to let the errors pass through as opposed to giving compile error "--log-error", // TODO spend more time figuring this out "--project", // TODO this should find the tsconfig.json and not assume there's one at the root but fine for now // same in generate_ts_code.go filepath.Join(rootPath, "tsconfig.json"), - "-r", - GetTsconfigPaths(), + // "-r", + // GetTsconfigPaths(), + } +} + +func UseSwc() bool { + return !util.EnvIsTrue("DISABLE_SWC") +} + +// func GetCommand() + +type CommandInfo struct { + Name string + Args []string + Env []string + UseSwc bool +} + +func GetCommandInfo(dirPath string, fromTest bool) *CommandInfo { + var env []string + cmdName := "ts-node" + var cmdArgs []string + useSwc := false + + if UseSwc() { + cmdArgs = append( + getArgsForScriptBoth(dirPath), + "-r", "@swc-node/register", + ) + + env = append(os.Environ(), "SWCRC=true") + + useSwc = true + } else if fromTest { + // TODO if in swc do we need this? + cmdArgs = []string{ + "--compiler-options", + testingutils.DefaultCompilerOptions(), + } + } else { + cmdName = "ts-node-script" + + cmdArgs = GetArgsForScript(dirPath) + } + + // append LOCAL_SCRIPT_PATH so we know. in typescript... + if util.EnvIsTrue("LOCAL_SCRIPT_PATH") { + env = append(env, "LOCAL_SCRIPT_PATH=true") + } + + return &CommandInfo{ + Name: cmdName, + Args: cmdArgs, + Env: env, + UseSwc: useSwc, } } diff --git a/internal/graphql/generate_ts_code.go b/internal/graphql/generate_ts_code.go index f3120ac7d..1abbf3563 100644 --- a/internal/graphql/generate_ts_code.go +++ b/internal/graphql/generate_ts_code.go @@ -33,7 +33,6 @@ import ( "github.com/lolopinto/ent/internal/schema/enum" "github.com/lolopinto/ent/internal/schema/input" "github.com/lolopinto/ent/internal/syncerr" - "github.com/lolopinto/ent/internal/testingutils" "github.com/lolopinto/ent/internal/tsimport" "github.com/lolopinto/ent/internal/util" "github.com/pkg/errors" @@ -661,41 +660,46 @@ func ParseRawCustomData(processor *codegen.Processor, fromTest bool) ([]byte, er buf.WriteString("\n") } - // similar to writeTsFile in parse_ts.go - // unfortunately that this is being done + scriptPath := util.GetPathToScript("scripts/custom_graphql.ts", fromTest) - var cmdName string - var cmdArgs []string - var env []string + cmdInfo := cmd.GetCommandInfo(processor.Config.GetAbsPathToRoot(), fromTest) + + if cmdInfo.UseSwc { + _, err := os.Stat(".swcrc") + if err != nil && os.IsNotExist(err) { + // temp .swcrc file to be used + // probably need this for parse_ts too + err = os.WriteFile(".swcrc", []byte(`{ + "jsc": { + "parser": { + "syntax": "typescript", + "decorators": true + }, + "target": "es2020", + "keepClassNames":true, + "transform": { + "decoratorVersion": "2022-03" + } + } +} + `), os.ModePerm) + + if err == nil { + defer os.Remove(".swcrc") + } + } + } - scriptPath := util.GetPathToScript("scripts/custom_graphql.ts", fromTest) if fromTest { - env = []string{ + cmdInfo.Env = append(cmdInfo.Env, fmt.Sprintf( "GRAPHQL_PATH=%s", filepath.Join(input.GetAbsoluteRootPathForTest(), "graphql"), ), - } - cmdName = "ts-node" - - cmdArgs = []string{ - "--compiler-options", - testingutils.DefaultCompilerOptions(), - } - } else { - cmdArgs = cmd.GetArgsForScript(processor.Config.GetAbsPathToRoot()) - - cmdName = "ts-node-script" - } - - // append LOCAL_SCRIPT_PATH so we know. in typescript... - if util.EnvIsTrue("LOCAL_SCRIPT_PATH") { - env = append(env, "LOCAL_SCRIPT_PATH=true") + ) } - cmdArgs = append(cmdArgs, - // TODO https://github.com/lolopinto/ent/issues/792 - // "--swc", + cmdArgs := append(cmdInfo.Args, scriptPath, "--path", // TODO this should be a configuration option to indicate where the code root is @@ -710,13 +714,13 @@ func ParseRawCustomData(processor *codegen.Processor, fromTest bool) ([]byte, er cmdArgs = append(cmdArgs, "--dynamic_path", dynamicPath) } - cmd := exec.Command(cmdName, cmdArgs...) + cmd := exec.Command(cmdInfo.Name, cmdArgs...) cmd.Dir = processor.Config.GetAbsPathToRoot() cmd.Stdin = &buf cmd.Stdout = &out cmd.Stderr = os.Stderr - if len(env) != 0 { - env2 := append(os.Environ(), env...) + if len(cmdInfo.Env) != 0 { + env2 := append(os.Environ(), cmdInfo.Env...) cmd.Env = env2 } diff --git a/internal/schema/input/parse_ts.go b/internal/schema/input/parse_ts.go index 02a7649b0..69756a089 100644 --- a/internal/schema/input/parse_ts.go +++ b/internal/schema/input/parse_ts.go @@ -9,7 +9,6 @@ import ( "strings" "github.com/lolopinto/ent/internal/cmd" - "github.com/lolopinto/ent/internal/testingutils" "github.com/lolopinto/ent/internal/util" "github.com/pkg/errors" ) @@ -35,34 +34,23 @@ func GetRawSchema(dirPath string, fromTest bool) ([]byte, error) { return nil, fmt.Errorf("expected schema to be a directory") } - var cmdArgs []string - cmdName := "ts-node" - if fromTest { - cmdArgs = []string{ - "--compiler-options", - testingutils.DefaultCompilerOptions(), - } - } else { - cmdName = "ts-node-script" - cmdArgs = cmd.GetArgsForScript(dirPath) - } - - if !util.EnvIsTrue("DISABLE_SWC") { - cmdArgs = append(cmdArgs, "--swc") - } + cmdInfo := cmd.GetCommandInfo(dirPath, fromTest) - cmdArgs = append( - cmdArgs, + cmdArgs := append( + cmdInfo.Args, util.GetPathToScript("scripts/read_schema.ts", fromTest), "--path", schemaPath, ) - execCmd := exec.Command(cmdName, cmdArgs...) + execCmd := exec.Command(cmdInfo.Name, cmdArgs...) var out bytes.Buffer var stderr bytes.Buffer execCmd.Stdout = &out execCmd.Stderr = &stderr + if cmdInfo.Env != nil { + execCmd.Env = cmdInfo.Env + } if err := execCmd.Run(); err != nil { str := stderr.String() err = errors.Wrap(err, str) diff --git a/internal/testingutils/compiler_options.go b/internal/testingutils/compiler_options.go index aa9eeb380..9a06b9ab1 100644 --- a/internal/testingutils/compiler_options.go +++ b/internal/testingutils/compiler_options.go @@ -8,7 +8,7 @@ import ( func DefaultCompilerOptions() string { opts, err := json.Marshal(map[string]interface{}{ - "lib": []string{"esnext", "dom"}, + "lib": []string{"esnext"}, "moduleResolution": "node", "downlevelIteration": true, "esModuleInterop": true, diff --git a/ts/package-lock.json b/ts/package-lock.json index bf6b56b12..15326aa7c 100644 --- a/ts/package-lock.json +++ b/ts/package-lock.json @@ -1,14 +1,15 @@ { "name": "@snowtop/ent", - "version": "0.1.0-alpha125", + "version": "0.1.0-alpha128", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@snowtop/ent", - "version": "0.1.0-alpha125", + "version": "0.1.0-alpha128", "license": "MIT", "dependencies": { + "@swc-node/register": "^1.6.5", "@types/node": "^18.11.18", "camel-case": "^4.1.2", "cosmiconfig": "^8.0.0", @@ -1207,11 +1208,85 @@ "@sinonjs/commons": "^1.7.0" } }, + "node_modules/@swc-node/core": { + "version": "1.10.3", + "resolved": "https://registry.npmjs.org/@swc-node/core/-/core-1.10.3.tgz", + "integrity": "sha512-8rpv1DXzsQjN/C8ZXuaTSmJ4M/lRr6geUlbOQ861DLC+sKWcEEvxRjK9cXQ28GserHuEcFDA3wlF9rD1YD0x+Q==", + "engines": { + "node": ">= 10" + }, + "funding": { + "type": "github", + "url": "https://github.com/sponsors/Brooooooklyn" + }, + "peerDependencies": { + "@swc/core": ">= 1.3" + } + }, + "node_modules/@swc-node/register": { + "version": "1.6.5", + "resolved": "https://registry.npmjs.org/@swc-node/register/-/register-1.6.5.tgz", + "integrity": "sha512-yMxXlzthI0aMadYYKDhx7xvtjljB1qoD8Tv0djqSJ1ttTkoDxg6MhG5A5pIahiUT2neVrkWb9lCavoUwXAe/zQ==", + "dependencies": { + "@swc-node/core": "^1.10.3", + "@swc-node/sourcemap-support": "^0.3.0", + "colorette": "^2.0.19", + "debug": "^4.3.4", + "pirates": "^4.0.5", + "tslib": "^2.5.0" + }, + "funding": { + "type": "github", + "url": "https://github.com/sponsors/Brooooooklyn" + }, + "peerDependencies": { + "@swc/core": ">= 1.3", + "typescript": ">= 4.3" + } + }, + "node_modules/@swc-node/register/node_modules/debug": { + "version": "4.3.4", + "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.4.tgz", + "integrity": "sha512-PRWFHuSU3eDtQJPvnNY7Jcket1j0t5OuOsFzPPzsekD52Zl8qUfFIPEiswXqIvHWGVHOgX+7G/vCNNhehwxfkQ==", + "dependencies": { + "ms": "2.1.2" + }, + "engines": { + "node": ">=6.0" + }, + "peerDependenciesMeta": { + "supports-color": { + "optional": true + } + } + }, + "node_modules/@swc-node/register/node_modules/ms": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", + "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==" + }, + "node_modules/@swc-node/sourcemap-support": { + "version": "0.3.0", + "resolved": "https://registry.npmjs.org/@swc-node/sourcemap-support/-/sourcemap-support-0.3.0.tgz", + "integrity": "sha512-gqBJSmJMWomZFxlppaKea7NeAqFrDrrS0RMt24No92M3nJWcyI9YKGEQKl+EyJqZ5gh6w1s0cTklMHMzRwA1NA==", + "dependencies": { + "source-map-support": "^0.5.21", + "tslib": "^2.5.0" + } + }, + "node_modules/@swc-node/sourcemap-support/node_modules/source-map-support": { + "version": "0.5.21", + "resolved": "https://registry.npmjs.org/source-map-support/-/source-map-support-0.5.21.tgz", + "integrity": "sha512-uBHU3L3czsIyYXKX88fdrGovxdSCoTGDRZ6SYXtSRxLZUzHg5P/66Ht6uoUlHu9EZod+inXhKo3qQgwXUT/y1w==", + "dependencies": { + "buffer-from": "^1.0.0", + "source-map": "^0.6.0" + } + }, "node_modules/@swc/core": { "version": "1.3.53", "resolved": "https://registry.npmjs.org/@swc/core/-/core-1.3.53.tgz", "integrity": "sha512-OM5nCfKDZXr1HjxD072Jlx5463tPX7xeY7NDSRE3X4KFlkRDFdyMWAyV3pet1oouOfUNrzzoVTAR4XSU8ytO6Q==", - "devOptional": true, "hasInstallScript": true, "engines": { "node": ">=10" @@ -2262,8 +2337,7 @@ "node_modules/buffer-from": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/buffer-from/-/buffer-from-1.1.2.tgz", - "integrity": "sha512-E+XQCRwSbaaiChtv6k6Dwgc+bx+Bs6vuKJHHl5kox/BaKbhiXzqQOwK4cO22yElGp2OCmjwVhT3HmxgyPGnJfQ==", - "dev": true + "integrity": "sha512-E+XQCRwSbaaiChtv6k6Dwgc+bx+Bs6vuKJHHl5kox/BaKbhiXzqQOwK4cO22yElGp2OCmjwVhT3HmxgyPGnJfQ==" }, "node_modules/buffer-writer": { "version": "2.0.0", @@ -2455,6 +2529,11 @@ "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==", "dev": true }, + "node_modules/colorette": { + "version": "2.0.20", + "resolved": "https://registry.npmjs.org/colorette/-/colorette-2.0.20.tgz", + "integrity": "sha512-IfEDxwoWIjkeXL1eXcDiow4UbKjhLdq6/EuSVR9GMN7KVH3r9gQ83e73hsz1Nd1T3ijd5xv1wcWRYO+D6kCI2w==" + }, "node_modules/combined-stream": { "version": "1.0.8", "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz", @@ -5260,7 +5339,6 @@ "version": "4.0.5", "resolved": "https://registry.npmjs.org/pirates/-/pirates-4.0.5.tgz", "integrity": "sha512-8V9+HQPupnaXMA23c5hvl69zXvTwTzyAYasnkb0Tts4XvO4CliqONMOnvlq26rkhLC3nWDFBJf73LU1e1VZLaQ==", - "dev": true, "engines": { "node": ">= 6" } @@ -5776,7 +5854,6 @@ "version": "0.6.1", "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz", "integrity": "sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==", - "dev": true, "engines": { "node": ">=0.10.0" } @@ -7534,11 +7611,64 @@ "@sinonjs/commons": "^1.7.0" } }, + "@swc-node/core": { + "version": "1.10.3", + "resolved": "https://registry.npmjs.org/@swc-node/core/-/core-1.10.3.tgz", + "integrity": "sha512-8rpv1DXzsQjN/C8ZXuaTSmJ4M/lRr6geUlbOQ861DLC+sKWcEEvxRjK9cXQ28GserHuEcFDA3wlF9rD1YD0x+Q==", + "requires": {} + }, + "@swc-node/register": { + "version": "1.6.5", + "resolved": "https://registry.npmjs.org/@swc-node/register/-/register-1.6.5.tgz", + "integrity": "sha512-yMxXlzthI0aMadYYKDhx7xvtjljB1qoD8Tv0djqSJ1ttTkoDxg6MhG5A5pIahiUT2neVrkWb9lCavoUwXAe/zQ==", + "requires": { + "@swc-node/core": "^1.10.3", + "@swc-node/sourcemap-support": "^0.3.0", + "colorette": "^2.0.19", + "debug": "^4.3.4", + "pirates": "^4.0.5", + "tslib": "^2.5.0" + }, + "dependencies": { + "debug": { + "version": "4.3.4", + "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.4.tgz", + "integrity": "sha512-PRWFHuSU3eDtQJPvnNY7Jcket1j0t5OuOsFzPPzsekD52Zl8qUfFIPEiswXqIvHWGVHOgX+7G/vCNNhehwxfkQ==", + "requires": { + "ms": "2.1.2" + } + }, + "ms": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", + "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==" + } + } + }, + "@swc-node/sourcemap-support": { + "version": "0.3.0", + "resolved": "https://registry.npmjs.org/@swc-node/sourcemap-support/-/sourcemap-support-0.3.0.tgz", + "integrity": "sha512-gqBJSmJMWomZFxlppaKea7NeAqFrDrrS0RMt24No92M3nJWcyI9YKGEQKl+EyJqZ5gh6w1s0cTklMHMzRwA1NA==", + "requires": { + "source-map-support": "^0.5.21", + "tslib": "^2.5.0" + }, + "dependencies": { + "source-map-support": { + "version": "0.5.21", + "resolved": "https://registry.npmjs.org/source-map-support/-/source-map-support-0.5.21.tgz", + "integrity": "sha512-uBHU3L3czsIyYXKX88fdrGovxdSCoTGDRZ6SYXtSRxLZUzHg5P/66Ht6uoUlHu9EZod+inXhKo3qQgwXUT/y1w==", + "requires": { + "buffer-from": "^1.0.0", + "source-map": "^0.6.0" + } + } + } + }, "@swc/core": { "version": "1.3.53", "resolved": "https://registry.npmjs.org/@swc/core/-/core-1.3.53.tgz", "integrity": "sha512-OM5nCfKDZXr1HjxD072Jlx5463tPX7xeY7NDSRE3X4KFlkRDFdyMWAyV3pet1oouOfUNrzzoVTAR4XSU8ytO6Q==", - "devOptional": true, "requires": { "@swc/core-darwin-arm64": "1.3.53", "@swc/core-darwin-x64": "1.3.53", @@ -8367,8 +8497,7 @@ "buffer-from": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/buffer-from/-/buffer-from-1.1.2.tgz", - "integrity": "sha512-E+XQCRwSbaaiChtv6k6Dwgc+bx+Bs6vuKJHHl5kox/BaKbhiXzqQOwK4cO22yElGp2OCmjwVhT3HmxgyPGnJfQ==", - "dev": true + "integrity": "sha512-E+XQCRwSbaaiChtv6k6Dwgc+bx+Bs6vuKJHHl5kox/BaKbhiXzqQOwK4cO22yElGp2OCmjwVhT3HmxgyPGnJfQ==" }, "buffer-writer": { "version": "2.0.0", @@ -8504,6 +8633,11 @@ "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==", "dev": true }, + "colorette": { + "version": "2.0.20", + "resolved": "https://registry.npmjs.org/colorette/-/colorette-2.0.20.tgz", + "integrity": "sha512-IfEDxwoWIjkeXL1eXcDiow4UbKjhLdq6/EuSVR9GMN7KVH3r9gQ83e73hsz1Nd1T3ijd5xv1wcWRYO+D6kCI2w==" + }, "combined-stream": { "version": "1.0.8", "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz", @@ -10683,8 +10817,7 @@ "pirates": { "version": "4.0.5", "resolved": "https://registry.npmjs.org/pirates/-/pirates-4.0.5.tgz", - "integrity": "sha512-8V9+HQPupnaXMA23c5hvl69zXvTwTzyAYasnkb0Tts4XvO4CliqONMOnvlq26rkhLC3nWDFBJf73LU1e1VZLaQ==", - "dev": true + "integrity": "sha512-8V9+HQPupnaXMA23c5hvl69zXvTwTzyAYasnkb0Tts4XvO4CliqONMOnvlq26rkhLC3nWDFBJf73LU1e1VZLaQ==" }, "pkg-dir": { "version": "4.2.0", @@ -11070,8 +11203,7 @@ "source-map": { "version": "0.6.1", "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz", - "integrity": "sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==", - "dev": true + "integrity": "sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==" }, "source-map-support": { "version": "0.5.13", diff --git a/ts/package.json b/ts/package.json index 1ddef31c0..2767cca09 100644 --- a/ts/package.json +++ b/ts/package.json @@ -1,6 +1,6 @@ { "name": "@snowtop/ent", - "version": "0.1.0-alpha128", + "version": "0.1.0-alpha128", "description": "snowtop ent framework", "main": "index.js", "types": "index.d.ts", @@ -8,6 +8,7 @@ "example": "examples" }, "dependencies": { + "@swc-node/register": "^1.6.5", "@types/node": "^18.11.18", "camel-case": "^4.1.2", "cosmiconfig": "^8.0.0", diff --git a/ts/src/scripts/custom_graphql.ts b/ts/src/scripts/custom_graphql.ts index 86b88ec3b..bc85fbd07 100644 --- a/ts/src/scripts/custom_graphql.ts +++ b/ts/src/scripts/custom_graphql.ts @@ -163,7 +163,13 @@ async function captureDynamic(filePath: string, gqlCapture: typeof GQLCapture) { if (process.env.DISABLE_SWC) { args.shift(); } - const r = spawn("ts-node", args); + // TODO support disable_swc flag + const r = spawn("node", ["-r", "@swc-node/register", filePath], { + env: { + ...process.env, + SWCRC: "true", + }, + }); const datas: string[] = []; r.stdout.on("data", (data) => { datas.push(data.toString());