payload 3.0.0-alpha.55 → 3.0.0-alpha.56
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin.js +1 -1
- package/dist/bin/loader/clientExtensions.d.ts.map +1 -0
- package/dist/bin/loader/clientExtensions.js.map +1 -0
- package/dist/bin/loader/compile.d.ts +5 -0
- package/dist/bin/loader/compile.d.ts.map +1 -0
- package/dist/bin/loader/compile.js +27 -0
- package/dist/bin/loader/compile.js.map +1 -0
- package/dist/bin/loader/index.d.ts.map +1 -0
- package/dist/bin/{register → loader}/index.js +22 -11
- package/dist/bin/loader/index.js.map +1 -0
- package/dist/bin/loader/read-default-tsconfig.d.ts.map +1 -0
- package/dist/bin/loader/read-default-tsconfig.js.map +1 -0
- package/package.json +2 -3
- package/dist/bin/register/clientExtensions.d.ts.map +0 -1
- package/dist/bin/register/clientExtensions.js.map +0 -1
- package/dist/bin/register/index.d.ts.map +0 -1
- package/dist/bin/register/index.js.map +0 -1
- package/dist/bin/register/read-default-tsconfig.d.ts.map +0 -1
- package/dist/bin/register/read-default-tsconfig.js.map +0 -1
- package/dist/bin/register/register.d.ts +0 -15
- package/dist/bin/register/register.d.ts.map +0 -1
- package/dist/bin/register/register.js +0 -92
- package/dist/bin/register/register.js.map +0 -1
- package/dist/config/load.d.ts +0 -6
- package/dist/config/load.d.ts.map +0 -1
- package/dist/config/load.js +0 -31
- package/dist/config/load.js.map +0 -1
- /package/dist/bin/{register → loader}/clientExtensions.d.ts +0 -0
- /package/dist/bin/{register → loader}/clientExtensions.js +0 -0
- /package/dist/bin/{register → loader}/index.d.ts +0 -0
- /package/dist/bin/{register → loader}/read-default-tsconfig.d.ts +0 -0
- /package/dist/bin/{register → loader}/read-default-tsconfig.js +0 -0
package/bin.js
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"clientExtensions.d.ts","sourceRoot":"","sources":["../../../src/bin/loader/clientExtensions.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,iBAAiB,UAU7B,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/bin/loader/clientExtensions.ts"],"sourcesContent":["export const CLIENT_EXTENSIONS = [\n '.scss',\n '.css',\n '.svg',\n '.png',\n '.jpg',\n '.eot',\n '.ttf',\n '.woff',\n '.woff2',\n]\n"],"names":["CLIENT_EXTENSIONS"],"mappings":"AAAA,OAAO,MAAMA,oBAAoB;IAC/B;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;CACD,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compile.d.ts","sourceRoot":"","sources":["../../../src/bin/loader/compile.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,EAAE,MAAM,YAAY,CAAA;AAyBrC,wBAAsB,OAAO,CAC3B,UAAU,EAAE,MAAM,EAClB,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,EAAE,CAAC,eAAe,GAAG;IAAE,YAAY,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,OAAO,CAAA;CAAE,GAC7E,OAAO,CAAC,MAAM,CAAC,CAUjB"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { transform } from '@swc-node/core';
|
|
2
|
+
import { SourcemapMap } from '@swc-node/sourcemap-support';
|
|
3
|
+
import { tsCompilerOptionsToSwcConfig } from './read-default-tsconfig.js';
|
|
4
|
+
const injectInlineSourceMap = ({ code, filename, map })=>{
|
|
5
|
+
if (map) {
|
|
6
|
+
SourcemapMap.set(filename, map);
|
|
7
|
+
const base64Map = Buffer.from(map, 'utf8').toString('base64');
|
|
8
|
+
const sourceMapContent = `//# sourceMappingURL=data:application/json;charset=utf-8;base64,${base64Map}`;
|
|
9
|
+
return `${code}\n${sourceMapContent}`;
|
|
10
|
+
}
|
|
11
|
+
return code;
|
|
12
|
+
};
|
|
13
|
+
export async function compile(sourcecode, filename, options) {
|
|
14
|
+
if (filename.endsWith('.d.ts')) {
|
|
15
|
+
return '';
|
|
16
|
+
}
|
|
17
|
+
const swcRegisterConfig = tsCompilerOptionsToSwcConfig(options, filename);
|
|
18
|
+
return transform(sourcecode, filename, swcRegisterConfig).then(({ code, map })=>{
|
|
19
|
+
return injectInlineSourceMap({
|
|
20
|
+
code,
|
|
21
|
+
filename,
|
|
22
|
+
map
|
|
23
|
+
});
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
//# sourceMappingURL=compile.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/bin/loader/compile.ts"],"sourcesContent":["import type * as ts from 'typescript'\n\nimport { transform } from '@swc-node/core'\nimport { SourcemapMap } from '@swc-node/sourcemap-support'\n\nimport { tsCompilerOptionsToSwcConfig } from './read-default-tsconfig.js'\n\nconst injectInlineSourceMap = ({\n code,\n filename,\n map,\n}: {\n code: string\n filename: string\n map: string | undefined\n}): string => {\n if (map) {\n SourcemapMap.set(filename, map)\n const base64Map = Buffer.from(map, 'utf8').toString('base64')\n const sourceMapContent = `//# sourceMappingURL=data:application/json;charset=utf-8;base64,${base64Map}`\n return `${code}\\n${sourceMapContent}`\n }\n return code\n}\n\nexport async function compile(\n sourcecode: string,\n filename: string,\n options: ts.CompilerOptions & { fallbackToTs?: (filename: string) => boolean },\n): Promise<string> {\n if (filename.endsWith('.d.ts')) {\n return ''\n }\n\n const swcRegisterConfig = tsCompilerOptionsToSwcConfig(options, filename)\n\n return transform(sourcecode, filename, swcRegisterConfig).then(({ code, map }) => {\n return injectInlineSourceMap({ code, filename, map })\n })\n}\n"],"names":["transform","SourcemapMap","tsCompilerOptionsToSwcConfig","injectInlineSourceMap","code","filename","map","set","base64Map","Buffer","from","toString","sourceMapContent","compile","sourcecode","options","endsWith","swcRegisterConfig","then"],"mappings":"AAEA,SAASA,SAAS,QAAQ,iBAAgB;AAC1C,SAASC,YAAY,QAAQ,8BAA6B;AAE1D,SA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AE,QAAQ,CAAC,WAAW,CAAC,KAAK,OAAO,CAAC,aAAa,CAAC,CAAA;AA8B3E,eAAO,MAAM,OAAO,EAAE,SA4DrB,CAAA;AAED,UAAU,WAAW;IACnB,UAAU,EAAE,MAAM,EAAE,CAAA;IACpB,MAAM,EAAE,IAAI,GAAG,MAAM,GAAG,SAAS,CAAA;CAClC;AACD,UAAU,UAAU;IAClB,MAAM,EAAE,MAAM,CAAA;IACd,YAAY,CAAC,EAAE,OAAO,CAAA;IACtB,MAAM,EAAE,WAAW,GAAG,iBAAiB,GAAG,UAAU,GAAG,MAAM,CAAA;CAC9D;AACD,KAAK,QAAQ,GAAG;IACd,GAAG,EAAE,MAAM;IACX,OAAO,EAAE,WAAW;IACpB,QAAQ,CAAC,EAAE,CAAC,GAAG,IAAI,EAAE,QAAQ,KAAK,OAAO,CAAC,UAAU,CAAC;CACtD,CAAA;AACD,KAAK,MAAM,GAAG,CAAC,GAAG,IAAI,EAAE,QAAQ,CAAC,QAAQ,CAAC,KAAK,OAAO,CAAC,UAAU,CAAC,CAAA;AAelE,eAAO,MAAM,IAAI,EAAE,MAuBlB,CAAA"}
|
|
@@ -3,24 +3,28 @@ import path from 'path';
|
|
|
3
3
|
import ts from 'typescript';
|
|
4
4
|
import { fileURLToPath, pathToFileURL } from 'url';
|
|
5
5
|
import { CLIENT_EXTENSIONS } from './clientExtensions.js';
|
|
6
|
-
import { compile } from './
|
|
6
|
+
import { compile } from './compile.js';
|
|
7
7
|
const locatedConfig = getTsconfig();
|
|
8
8
|
const tsconfig = locatedConfig.config.compilerOptions;
|
|
9
9
|
tsconfig.module = ts.ModuleKind.ESNext;
|
|
10
|
-
|
|
10
|
+
// Specify bundler resolution for Next.js compatibility.
|
|
11
|
+
// We will use TS to resolve file paths for most flexibility
|
|
12
|
+
tsconfig.moduleResolution = ts.ModuleResolutionKind.Bundler;
|
|
13
|
+
// Don't resolve d.ts files, because we aren't type-checking
|
|
14
|
+
tsconfig.noDtsResolution = true;
|
|
11
15
|
const moduleResolutionCache = ts.createModuleResolutionCache(ts.sys.getCurrentDirectory(), (x)=>x, tsconfig);
|
|
12
16
|
const host = {
|
|
13
17
|
fileExists: ts.sys.fileExists,
|
|
14
18
|
readFile: ts.sys.readFile
|
|
15
19
|
};
|
|
16
|
-
const
|
|
20
|
+
const TS_EXTENSIONS = [
|
|
17
21
|
ts.Extension.Ts,
|
|
18
22
|
ts.Extension.Tsx,
|
|
19
23
|
ts.Extension.Dts,
|
|
20
24
|
ts.Extension.Mts
|
|
21
25
|
];
|
|
22
26
|
export const resolve = async (specifier, context, nextResolve)=>{
|
|
23
|
-
const isTS =
|
|
27
|
+
const isTS = TS_EXTENSIONS.some((ext)=>specifier.endsWith(ext));
|
|
24
28
|
const isClient = CLIENT_EXTENSIONS.some((ext)=>specifier.endsWith(ext));
|
|
25
29
|
if (isClient) {
|
|
26
30
|
const nextResult = await nextResolve(specifier, context, nextResolve);
|
|
@@ -45,12 +49,19 @@ export const resolve = async (specifier, context, nextResolve)=>{
|
|
|
45
49
|
}
|
|
46
50
|
const { resolvedModule } = ts.resolveModuleName(specifier, fileURLToPath(context.parentURL), tsconfig, host, moduleResolutionCache);
|
|
47
51
|
// import from local project to local project TS file
|
|
48
|
-
if (resolvedModule
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
52
|
+
if (resolvedModule) {
|
|
53
|
+
const resolvedIsNodeModule = resolvedModule.resolvedFileName.includes('/node_modules/');
|
|
54
|
+
const resolvedIsTS = TS_EXTENSIONS.includes(resolvedModule.extension);
|
|
55
|
+
if (!resolvedIsNodeModule && resolvedIsTS) {
|
|
56
|
+
return {
|
|
57
|
+
format: 'ts',
|
|
58
|
+
shortCircuit: true,
|
|
59
|
+
url: pathToFileURL(resolvedModule.resolvedFileName).href
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
// We want to use TS "Bundler" moduleResolution for just about all files
|
|
63
|
+
// so we pass the TS result here
|
|
64
|
+
return nextResolve(pathToFileURL(resolvedModule.resolvedFileName).href);
|
|
54
65
|
}
|
|
55
66
|
// import from local project to either:
|
|
56
67
|
// - something TS couldn't resolve
|
|
@@ -81,7 +92,7 @@ export const load = async (url, context, nextLoad)=>{
|
|
|
81
92
|
if (context.format === 'ts') {
|
|
82
93
|
const { source } = await nextLoad(url, context);
|
|
83
94
|
const code = typeof source === 'string' ? source : Buffer.from(source).toString();
|
|
84
|
-
const compiled = await compile(code, fileURLToPath(url), swcOptions
|
|
95
|
+
const compiled = await compile(code, fileURLToPath(url), swcOptions);
|
|
85
96
|
return {
|
|
86
97
|
format: 'module',
|
|
87
98
|
shortCircuit: true,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/bin/loader/index.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/unbound-method */\nimport { getTsconfig } from 'get-tsconfig'\nimport path from 'path'\nimport ts from 'typescript'\nimport { fileURLToPath, pathToFileURL } from 'url'\n\nimport { CLIENT_EXTENSIONS } from './clientExtensions.js'\nimport { compile } from './compile.js'\n\ninterface ResolveContext {\n conditions: string[]\n parentURL: string | undefined\n}\ninterface ResolveResult {\n format?: string\n shortCircuit?: boolean\n url: string\n}\ntype ResolveArgs = [\n specifier: string,\n context?: ResolveContext,\n nextResolve?: (...args: ResolveArgs) => Promise<ResolveResult>,\n]\ntype ResolveFn = (...args: Required<ResolveArgs>) => Promise<ResolveResult>\n\nconst locatedConfig = getTsconfig()\nconst tsconfig = locatedConfig.config.compilerOptions as unknown as ts.CompilerOptions\n\ntsconfig.module = ts.ModuleKind.ESNext\n\n// Specify bundler resolution for Next.js compatibility.\n// We will use TS to resolve file paths for most flexibility\ntsconfig.moduleResolution = ts.ModuleResolutionKind.Bundler\n\n// Don't resolve d.ts files, because we aren't type-checking\ntsconfig.noDtsResolution = true\n\nconst moduleResolutionCache = ts.createModuleResolutionCache(\n ts.sys.getCurrentDirectory(),\n (x) => x,\n tsconfig,\n)\nconst host: ts.ModuleResolutionHost = {\n fileExists: ts.sys.fileExists,\n readFile: ts.sys.readFile,\n}\nconst TS_EXTENSIONS: string[] = [\n ts.Extension.Ts,\n ts.Extension.Tsx,\n ts.Extension.Dts,\n ts.Extension.Mts,\n]\n\nexport const resolve: ResolveFn = async (specifier, context, nextResolve) => {\n const isTS = TS_EXTENSIONS.some((ext) => specifier.endsWith(ext))\n const isClient = CLIENT_EXTENSIONS.some((ext) => specifier.endsWith(ext))\n\n if (isClient) {\n const nextResult = await nextResolve(specifier, context, nextResolve)\n const specifierSegments = specifier.split('.')\n\n return {\n format: '.' + specifierSegments[specifierSegments.length - 1],\n shortCircuit: true,\n url: nextResult.url,\n }\n }\n\n // entrypoint\n if (!context.parentURL) {\n return {\n format: isTS ? 'ts' : undefined,\n shortCircuit: true,\n url: specifier,\n }\n }\n\n // import/require from external library\n if (context.parentURL.includes('/node_modules/') && !isTS) {\n return nextResolve(specifier)\n }\n\n const { resolvedModule } = ts.resolveModuleName(\n specifier,\n fileURLToPath(context.parentURL),\n tsconfig,\n host,\n moduleResolutionCache,\n )\n\n // import from local project to local project TS file\n if (resolvedModule) {\n const resolvedIsNodeModule = resolvedModule.resolvedFileName.includes('/node_modules/')\n const resolvedIsTS = TS_EXTENSIONS.includes(resolvedModule.extension)\n\n if (!resolvedIsNodeModule && resolvedIsTS) {\n return {\n format: 'ts',\n shortCircuit: true,\n url: pathToFileURL(resolvedModule.resolvedFileName).href,\n }\n }\n\n // We want to use TS \"Bundler\" moduleResolution for just about all files\n // so we pass the TS result here\n return nextResolve(pathToFileURL(resolvedModule.resolvedFileName).href)\n }\n\n // import from local project to either:\n // - something TS couldn't resolve\n // - external library\n // - local project non-TS file\n return nextResolve(specifier)\n}\n\ninterface LoadContext {\n conditions: string[]\n format: null | string | undefined\n}\ninterface LoadResult {\n format: string\n shortCircuit?: boolean\n source: ArrayBuffer | SharedArrayBuffer | Uint8Array | string\n}\ntype LoadArgs = [\n url: string,\n context: LoadContext,\n nextLoad?: (...args: LoadArgs) => Promise<LoadResult>,\n]\ntype LoadFn = (...args: Required<LoadArgs>) => Promise<LoadResult>\n\nconst swcOptions = {\n ...tsconfig,\n baseUrl: path.resolve(''),\n paths: undefined,\n}\n\nif (tsconfig.paths) {\n swcOptions.paths = tsconfig.paths\n if (tsconfig.baseUrl) {\n swcOptions.baseUrl = path.resolve(tsconfig.baseUrl)\n }\n}\n\nexport const load: LoadFn = async (url, context, nextLoad) => {\n if (CLIENT_EXTENSIONS.some((e) => context.format === e)) {\n const rawSource = '{}'\n\n return {\n format: 'json',\n shortCircuit: true,\n source: rawSource,\n }\n }\n\n if (context.format === 'ts') {\n const { source } = await nextLoad(url, context)\n const code = typeof source === 'string' ? source : Buffer.from(source).toString()\n const compiled = await compile(code, fileURLToPath(url), swcOptions)\n return {\n format: 'module',\n shortCircuit: true,\n source: compiled,\n }\n } else {\n return nextLoad(url, context)\n }\n}\n"],"names":["getTsconfig","path","ts","fileURLToPath","pathToFileURL","CLIENT_EXTENSIONS","compile","locatedConfig","tsconfig","config","compilerOptions","module","ModuleKind","ESNext","moduleResolution","ModuleResolutionKind","Bundler","noDtsResolution","moduleResolutionCache","createModuleResolutionCache","sys","getCurrentDirectory","x","host","fileExists","readFile","TS_EXTENSIONS","Extension","Ts","Tsx","Dts","Mts","resolve","specifier","context","nextResolve","isTS","some","ext","endsWith","isClient","nextResult","specifierSegments","split","format","length","shortCircuit","url","parentURL","undefined","includes","resolvedModule","resolveModuleName","resolvedIsNodeModule","resolvedFileName","resolvedIsTS","extension","href","swcOptions","baseUrl","paths","load","nextLoad","e","rawSource","source","code","Buffer","from","toString","compiled"],"mappings":"AAAA,oDAAoD,GACpD,SAASA,WAAW,QAAQ,eAAc;AAC1C,OAAOC,UAAU,OAAM;AACvB,OAAOC,QAAQ,aAAY;AAC3B,SAASC,aAAa,EAAEC,aAAa,QAAQ,MAAK;AAElD,SAASC,iBAAiB,QAAQ,wBAAuB;AACzD,SAASC,OAAO,QAAQ,eAAc;AAk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,EAAE,GAAG,MAAMH,SAASf,KAAKb;QACvC,MAAMgC,OAAO,OAAOD,WAAW,WAAWA,SAASE,OAAOC,IAAI,CAACH,QAAQI,QAAQ;QAC/E,MAAMC,WAAW,MAAMhE,QAAQ4D,MAAM/D,cAAc4C,MAAMW;QACzD,OAAO;YACLd,QAAQ;YACRE,cAAc;YACdmB,QAAQK;QACV;IACF,OAAO;QACL,OAAOR,SAASf,KAAKb;IACvB;AACF,EAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"read-default-tsconfig.d.ts","sourceRoot":"","sources":["../../../src/bin/loader/read-default-tsconfig.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAA;AAG7C,OAAO,EAAE,MAAM,YAAY,CAAA;AA+D3B,wBAAgB,4BAA4B,CAC1C,OAAO,EAAE,EAAE,CAAC,eAAe,EAC3B,QAAQ,EAAE,MAAM,GACf,OAAO,CAsCT"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/bin/loader/read-default-tsconfig.ts"],"sourcesContent":["import type { Options } from '@swc-node/core'\n\nimport { resolve } from 'path'\nimport ts from 'typescript'\n\nfunction toTsTarget(target: ts.ScriptTarget): Options['target'] {\n switch (target) {\n case ts.ScriptTarget.ES3:\n return 'es3'\n case ts.ScriptTarget.ES5:\n return 'es5'\n case ts.ScriptTarget.ES2015:\n return 'es2015'\n case ts.ScriptTarget.ES2016:\n return 'es2016'\n case ts.ScriptTarget.ES2017:\n return 'es2017'\n case ts.ScriptTarget.ES2018:\n return 'es2018'\n case ts.ScriptTarget.ES2019:\n return 'es2019'\n case ts.ScriptTarget.ES2020:\n return 'es2020'\n case ts.ScriptTarget.ES2021:\n return 'es2021'\n case ts.ScriptTarget.ES2022:\n case ts.ScriptTarget.ESNext:\n case ts.ScriptTarget.Latest:\n return 'es2022'\n case ts.ScriptTarget.JSON:\n return 'es5'\n }\n}\n\nfunction toModule(moduleKind: ts.ModuleKind) {\n switch (moduleKind) {\n case ts.ModuleKind.CommonJS:\n return 'commonjs'\n case ts.ModuleKind.UMD:\n return 'umd'\n case ts.ModuleKind.AMD:\n return 'amd'\n case ts.ModuleKind.ES2015:\n case ts.ModuleKind.ES2020:\n case ts.ModuleKind.ES2022:\n case ts.ModuleKind.ESNext:\n case ts.ModuleKind.Node16:\n case ts.ModuleKind.NodeNext:\n case ts.ModuleKind.None:\n return 'es6'\n case ts.ModuleKind.System:\n throw new TypeError('Do not support system kind module')\n }\n}\n\n/**\n * The default value for useDefineForClassFields depends on the emit target\n * @see https://www.typescriptlang.org/tsconfig#useDefineForClassFields\n */\nfunction getUseDefineForClassFields(\n compilerOptions: ts.CompilerOptions,\n target: ts.ScriptTarget,\n): boolean {\n return compilerOptions.useDefineForClassFields ?? target >= ts.ScriptTarget.ES2022\n}\n\nexport function tsCompilerOptionsToSwcConfig(\n options: ts.CompilerOptions,\n filename: string,\n): Options {\n const isJsx = filename.endsWith('.tsx') || filename.endsWith('.jsx') || Boolean(options.jsx)\n const target = options.target ?? ts.ScriptTarget.ES2018\n return {\n baseUrl: options.baseUrl ? resolve(options.baseUrl) : undefined,\n dynamicImport: true,\n emitDecoratorMetadata: options.emitDecoratorMetadata ?? false,\n esModuleInterop: options.esModuleInterop ?? false,\n experimentalDecorators: options.experimentalDecorators ?? false,\n externalHelpers: Boolean(options.importHelpers),\n ignoreDynamic: Boolean(process.env.SWC_NODE_IGNORE_DYNAMIC),\n jsx: isJsx,\n keepClassNames: true,\n module: toModule(options.module ?? ts.ModuleKind.ES2015),\n paths: Object.fromEntries(\n Object.entries(options.paths ?? {}).map(([aliasKey, aliasPaths]) => [\n aliasKey,\n (aliasPaths ?? []).map((path) => resolve(options.baseUrl ?? './', path)),\n ]),\n ) as Options['paths'],\n react:\n options.jsxFactory ?? options.jsxFragmentFactory ?? options.jsx ?? options.jsxImportSource\n ? {\n importSource: options.jsxImportSource ?? 'react',\n pragma: options.jsxFactory,\n pragmaFrag: options.jsxFragmentFactory,\n runtime: (options.jsx ?? 0) >= ts.JsxEmit.ReactJSX ? 'automatic' : 'classic',\n useBuiltins: true,\n }\n : undefined,\n sourcemap: options.sourceMap && options.inlineSourceMap ? 'inline' : Boolean(options.sourceMap),\n swc: {\n inputSourceMap: options.inlineSourceMap,\n sourceRoot: options.sourceRoot,\n },\n target: toTsTarget(target),\n useDefineForClassFields: getUseDefineForClassFields(options, target),\n }\n}\n"],"names":["resolve","ts","toTsTarget","target","ScriptTarget","ES3","ES5","ES2015","ES2016","ES2017","ES2018","ES2019","ES2020","ES2021","ES2022","ESNext","Latest","JSON","toModule","moduleKind","ModuleKind","CommonJS","UMD","AMD","Node16","NodeNext","None","System","TypeError","getUseDefineForClassFields","compilerOptions","useDefineForClassFields","tsCompilerOptionsToSwcConfig","options","filename","isJsx","endsWith","Boolean","jsx","baseUrl","undefined","dynamicImport","emitDecoratorMetadata","esModuleInterop","experimentalDecorators","externalHelpers","importHelpers","ignoreDynamic","process","env","SWC_NODE_IGNORE_DYNAMIC","keepClassNames","module","paths","Object","fromEntries","entries","map","aliasKey","aliasPaths","path","react","jsxFactory","jsxFragmentFactory","jsxImportSource","importSource","pragma","pragmaFrag","runtime","JsxEmit","ReactJSX","useBuiltins","sourcemap","sourceMap","inlineSourceMap","swc","inputSourceMap","sourceRoot"],"mappings":"AAEA,SAASA,OAAO,QAAQ,OAAM;AAC9B,OAAOC,QAAQ,aAAY;AAE3B,SAASC,WAAWC,MAAuB;IACzC,OAAQA;QACN,KAAKF,GAAGG,YAAY,CAACC,GAAG;YACtB,OAAO;QACT,KAAKJ,GAAGG,YAAY,CAACE,GAAG;YACtB,OAAO;QACT,KAAKL,GAAGG,YAAY,CAACG,MAAM;YACzB,OAAO;QACT,KAAKN,GAAGG,YAAY,CAACI,MAAM;YACzB,OAAO;QACT,KAAKP,GAAGG,YAAY,CAACK,MAAM;YACzB,OAAO;QACT,KAAKR,GAAGG,YAAY,CAACM,MAA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BAA2BI,SAAS9B;IAC/D;AACF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "payload",
|
|
3
|
-
"version": "3.0.0-alpha.
|
|
3
|
+
"version": "3.0.0-alpha.56",
|
|
4
4
|
"description": "Node, React and MongoDB Headless CMS and Application Framework",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -44,13 +44,12 @@
|
|
|
44
44
|
"nodemailer": "6.9.10",
|
|
45
45
|
"pino": "8.15.0",
|
|
46
46
|
"pino-pretty": "10.2.0",
|
|
47
|
-
"pirates": "^4.0.6",
|
|
48
47
|
"pluralize": "8.0.0",
|
|
49
48
|
"probe-image-size": "^7.2.3",
|
|
50
49
|
"sanitize-filename": "1.6.3",
|
|
51
50
|
"scheduler": "0.23.0",
|
|
52
51
|
"scmp": "2.1.0",
|
|
53
|
-
"@payloadcms/translations": "3.0.0-alpha.
|
|
52
|
+
"@payloadcms/translations": "3.0.0-alpha.54"
|
|
54
53
|
},
|
|
55
54
|
"devDependencies": {
|
|
56
55
|
"@monaco-editor/react": "4.5.1",
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"clientExtensions.d.ts","sourceRoot":"","sources":["../../../src/bin/register/clientExtensions.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,iBAAiB,UAU7B,CAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/bin/register/clientExtensions.ts"],"sourcesContent":["export const CLIENT_EXTENSIONS = [\n '.scss',\n '.css',\n '.svg',\n '.png',\n '.jpg',\n '.eot',\n '.ttf',\n '.woff',\n '.woff2',\n]\n"],"names":["CLIENT_EXTENSIONS"],"mappings":"AAAA,OAAO,MAAMA,oBAAoB;IAC/B;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;CACD,CAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"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|
|
1
|
-
{"version":3,"sources":["../../../src/bin/register/index.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/unbound-method */\nimport { getTsconfig } from 'get-tsconfig'\nimport path from 'path'\nimport ts from 'typescript'\nimport { fileURLToPath, pathToFileURL } from 'url'\n\nimport { CLIENT_EXTENSIONS } from './clientExtensions.js'\nimport { compile } from './register.js'\n\ninterface ResolveContext {\n conditions: string[]\n parentURL: string | undefined\n}\ninterface ResolveResult {\n format?: string\n shortCircuit?: boolean\n url: string\n}\ntype ResolveArgs = [\n specifier: string,\n context?: ResolveContext,\n nextResolve?: (...args: ResolveArgs) => Promise<ResolveResult>,\n]\ntype ResolveFn = (...args: Required<ResolveArgs>) => Promise<ResolveResult>\n\nconst locatedConfig = getTsconfig()\nconst tsconfig = locatedConfig.config.compilerOptions as unknown as ts.CompilerOptions\n\ntsconfig.module = ts.ModuleKind.ESNext\ntsconfig.moduleResolution = ts.ModuleResolutionKind.NodeNext\n\nconst moduleResolutionCache = ts.createModuleResolutionCache(\n ts.sys.getCurrentDirectory(),\n (x) => x,\n tsconfig,\n)\nconst host: ts.ModuleResolutionHost = {\n fileExists: ts.sys.fileExists,\n readFile: ts.sys.readFile,\n}\nconst EXTENSIONS: string[] = [ts.Extension.Ts, ts.Extension.Tsx, ts.Extension.Dts, ts.Extension.Mts]\n\nexport const resolve: ResolveFn = async (specifier, context, nextResolve) => {\n const isTS = EXTENSIONS.some((ext) => specifier.endsWith(ext))\n const isClient = CLIENT_EXTENSIONS.some((ext) => specifier.endsWith(ext))\n\n if (isClient) {\n const nextResult = await nextResolve(specifier, context, nextResolve)\n const specifierSegments = specifier.split('.')\n\n return {\n format: '.' + specifierSegments[specifierSegments.length - 1],\n shortCircuit: true,\n url: nextResult.url,\n }\n }\n\n // entrypoint\n if (!context.parentURL) {\n return {\n format: isTS ? 'ts' : undefined,\n shortCircuit: true,\n url: specifier,\n }\n }\n\n // import/require from external library\n if (context.parentURL.includes('/node_modules/') && !isTS) {\n return nextResolve(specifier)\n }\n\n const { resolvedModule } = ts.resolveModuleName(\n specifier,\n fileURLToPath(context.parentURL),\n tsconfig,\n host,\n moduleResolutionCache,\n )\n\n // import from local project to local project TS file\n if (\n resolvedModule &&\n !resolvedModule.resolvedFileName.includes('/node_modules/') &&\n EXTENSIONS.includes(resolvedModule.extension)\n ) {\n return {\n format: 'ts',\n shortCircuit: true,\n url: pathToFileURL(resolvedModule.resolvedFileName).href,\n }\n }\n\n // import from local project to either:\n // - something TS couldn't resolve\n // - external library\n // - local project non-TS file\n return nextResolve(specifier)\n}\n\ninterface LoadContext {\n conditions: string[]\n format: null | string | undefined\n}\ninterface LoadResult {\n format: string\n shortCircuit?: boolean\n source: ArrayBuffer | SharedArrayBuffer | Uint8Array | string\n}\ntype LoadArgs = [\n url: string,\n context: LoadContext,\n nextLoad?: (...args: LoadArgs) => Promise<LoadResult>,\n]\ntype LoadFn = (...args: Required<LoadArgs>) => Promise<LoadResult>\n\nconst swcOptions = {\n ...tsconfig,\n baseUrl: path.resolve(''),\n paths: undefined,\n}\n\nif (tsconfig.paths) {\n swcOptions.paths = tsconfig.paths\n if (tsconfig.baseUrl) {\n swcOptions.baseUrl = path.resolve(tsconfig.baseUrl)\n }\n}\n\nexport const load: LoadFn = async (url, context, nextLoad) => {\n if (CLIENT_EXTENSIONS.some((e) => context.format === e)) {\n const rawSource = '{}'\n\n return {\n format: 'json',\n shortCircuit: true,\n source: rawSource,\n }\n }\n\n if (context.format === 'ts') {\n const { source } = await nextLoad(url, context)\n const code = typeof source === 'string' ? source : Buffer.from(source).toString()\n const compiled = await compile(code, fileURLToPath(url), swcOptions, true)\n return {\n format: 'module',\n shortCircuit: true,\n source: compiled,\n }\n } else {\n return nextLoad(url, context)\n }\n}\n"],"names":["getTsconfig","path","ts","fileURLToPath","pathToFileURL","CLIENT_EXTENSIONS","compile","locatedConfig","tsconfig","config","compilerOptions","module","ModuleKind","ESNext","moduleResolution","ModuleResolutionKind","NodeNext","moduleResolutionCache","createModuleResolutionCache","sys","getCurrentDirectory","x","host","fileExists","readFile","EXTENSIONS","Extension","Ts","Tsx","Dts","Mts","resolve","specifier","context","nextResolve","isTS","some","ext","endsWith","isClient","nextResult","specifierSegments","split","format","length","shortCircuit","url","parentURL","undefined","includes","resolvedModule","resolveModuleName","resolvedFileName","extension","href","swcOptions","baseUrl","paths","load","nextLoad","e","rawSource","source","code","Buffer","from","toString","compiled"],"mappings":"AAAA,oDAAoD,GACpD,SAASA,WAAW,QAAQ,eAAc;AAC1C,OAAOC,UAAU,OAAM;AACvB,OAAOC,QAAQ,aAAY;AAC3B,SAASC,aAAa,EAAEC,aAAa,QAAQ,MAAK;AAElD,SAASC,iBAAiB,QAAQ,wBAAuB;AACzD,SAASC,OAAO,QAAQ,gBAAe;AAkBvC,MAAMC,gBAAgBP;AACtB,MAAMQ,WAAWD,cAAcE,MAAM,CAACC,eAAe;AAErDF,SAASG,MAAM,GAAGT,GAAGU,UAAU,CAACC,MAAM;AACtCL,SAASM,gBAAgB,GAAGZ,GAAGa,oBAAoB,CAACC,QAAQ;AAE5D,MAAMC,wBAAwBf,GAAGgB,2BAA2B,CAC1DhB,GAAGiB,GAAG,CAACC,mBAAmB,IAC1B,CAACC,IAAMA,GACPb;AAEF,MAAMc,OAAgC;IACpCC,YAAYrB,GAAGiB,GAAG,CAACI,UAAU;IAC7BC,UAAUtB,GAAGiB,GAAG,CAACK,QAAQ;AAC3B;AACA,MAAMC,aAAuB;IAACvB,GAAGwB,SAAS,CAACC,EAAE;IAAEzB,GAAGwB,SAAS,CAACE,GAAG;IAAE1B,GAAGwB,SAAS,CAACG,GAAG;IAAE3B,GAAGwB,SAAS,CAACI,GAAG;CAAC;AAEpG,OAAO,MAAMC,UAAqB,OAAOC,WAAWC,SAASC;IAC3D,MAAMC,OAAOV,WAAWW,IAAI,CAAC,CAACC,MAAQL,UAAUM,QAAQ,CAACD;IACzD,MAAME,WAAWlC,kBAAkB+B,IAAI,CAAC,CAACC,MAAQL,UAAUM,Q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,KAAKb,SAAS0B;IAC/C,IAAItD,kBAAkB+B,IAAI,CAAC,CAACwB,IAAM3B,QAAQU,MAAM,KAAKiB,IAAI;QACvD,MAAMC,YAAY;QAElB,OAAO;YACLlB,QAAQ;YACRE,cAAc;YACdiB,QAAQD;QACV;IACF;IAEA,IAAI5B,QAAQU,MAAM,KAAK,MAAM;QAC3B,MAAM,EAAEmB,MAAM,EAAE,GAAG,MAAMH,SAASb,KAAKb;QACvC,MAAM8B,OAAO,OAAOD,WAAW,WAAWA,SAASE,OAAOC,IAAI,CAACH,QAAQI,QAAQ;QAC/E,MAAMC,WAAW,MAAM7D,QAAQyD,MAAM5D,cAAc2C,MAAMS,YAAY;QACrE,OAAO;YACLZ,QAAQ;YACRE,cAAc;YACdiB,QAAQK;QACV;IACF,OAAO;QACL,OAAOR,SAASb,KAAKb;IACvB;AACF,EAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"read-default-tsconfig.d.ts","sourceRoot":"","sources":["../../../src/bin/register/read-default-tsconfig.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAA;AAG7C,OAAO,EAAE,MAAM,YAAY,CAAA;AA+D3B,wBAAgB,4BAA4B,CAC1C,OAAO,EAAE,EAAE,CAAC,eAAe,EAC3B,QAAQ,EAAE,MAAM,GACf,OAAO,CAsCT"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/bin/register/read-default-tsconfig.ts"],"sourcesContent":["import type { Options } from '@swc-node/core'\n\nimport { resolve } from 'path'\nimport ts from 'typescript'\n\nfunction toTsTarget(target: ts.ScriptTarget): Options['target'] {\n switch (target) {\n case ts.ScriptTarget.ES3:\n return 'es3'\n case ts.ScriptTarget.ES5:\n return 'es5'\n case ts.ScriptTarget.ES2015:\n return 'es2015'\n case ts.ScriptTarget.ES2016:\n return 'es2016'\n case ts.ScriptTarget.ES2017:\n return 'es2017'\n case ts.ScriptTarget.ES2018:\n return 'es2018'\n case ts.ScriptTarget.ES2019:\n return 'es2019'\n case ts.ScriptTarget.ES2020:\n return 'es2020'\n case ts.ScriptTarget.ES2021:\n return 'es2021'\n case ts.ScriptTarget.ES2022:\n case ts.ScriptTarget.ESNext:\n case ts.ScriptTarget.Latest:\n return 'es2022'\n case ts.ScriptTarget.JSON:\n return 'es5'\n }\n}\n\nfunction toModule(moduleKind: ts.ModuleKind) {\n switch (moduleKind) {\n case ts.ModuleKind.CommonJS:\n return 'commonjs'\n case ts.ModuleKind.UMD:\n return 'umd'\n case ts.ModuleKind.AMD:\n return 'amd'\n case ts.ModuleKind.ES2015:\n case ts.ModuleKind.ES2020:\n case ts.ModuleKind.ES2022:\n case ts.ModuleKind.ESNext:\n case ts.ModuleKind.Node16:\n case ts.ModuleKind.NodeNext:\n case ts.ModuleKind.None:\n return 'es6'\n case ts.ModuleKind.System:\n throw new TypeError('Do not support system kind module')\n }\n}\n\n/**\n * The default value for useDefineForClassFields depends on the emit target\n * @see https://www.typescriptlang.org/tsconfig#useDefineForClassFields\n */\nfunction getUseDefineForClassFields(\n compilerOptions: ts.CompilerOptions,\n target: ts.ScriptTarget,\n): boolean {\n return compilerOptions.useDefineForClassFields ?? target >= ts.ScriptTarget.ES2022\n}\n\nexport function tsCompilerOptionsToSwcConfig(\n options: ts.CompilerOptions,\n filename: string,\n): Options {\n const isJsx = filename.endsWith('.tsx') || filename.endsWith('.jsx') || Boolean(options.jsx)\n const target = options.target ?? ts.ScriptTarget.ES2018\n return {\n baseUrl: options.baseUrl ? resolve(options.baseUrl) : undefined,\n dynamicImport: true,\n emitDecoratorMetadata: options.emitDecoratorMetadata ?? false,\n esModuleInterop: options.esModuleInterop ?? false,\n experimentalDecorators: options.experimentalDecorators ?? false,\n externalHelpers: Boolean(options.importHelpers),\n ignoreDynamic: Boolean(process.env.SWC_NODE_IGNORE_DYNAMIC),\n jsx: isJsx,\n keepClassNames: true,\n module: toModule(options.module ?? ts.ModuleKind.ES2015),\n paths: Object.fromEntries(\n Object.entries(options.paths ?? {}).map(([aliasKey, aliasPaths]) => [\n aliasKey,\n (aliasPaths ?? []).map((path) => resolve(options.baseUrl ?? './', path)),\n ]),\n ) as Options['paths'],\n react:\n options.jsxFactory ?? options.jsxFragmentFactory ?? options.jsx ?? options.jsxImportSource\n ? {\n importSource: options.jsxImportSource ?? 'react',\n pragma: options.jsxFactory,\n pragmaFrag: options.jsxFragmentFactory,\n runtime: (options.jsx ?? 0) >= ts.JsxEmit.ReactJSX ? 'automatic' : 'classic',\n useBuiltins: true,\n }\n : undefined,\n sourcemap: options.sourceMap && options.inlineSourceMap ? 'inline' : Boolean(options.sourceMap),\n swc: {\n inputSourceMap: options.inlineSourceMap,\n sourceRoot: options.sourceRoot,\n },\n target: toTsTarget(target),\n useDefineForClassFields: getUseDefineForClassFields(options, target),\n }\n}\n"],"names":["resolve","ts","toTsTarget","target","ScriptTarget","ES3","ES5","ES2015","ES2016","ES2017","ES2018","ES2019","ES2020","ES2021","ES2022","ESNext","Latest","JSON","toModule","moduleKind","ModuleKind","CommonJS","UMD","AMD","Node16","NodeNext","None","System","TypeError","getUseDefineForClassFields","compilerOptions","useDefineForClassFields","tsCompilerOptionsToSwcConfig","options","filename","isJsx","endsWith","Boolean","jsx","baseUrl","undefined","dynamicImport","emitDecoratorMetadata","esModuleInterop","experimentalDecorators","externalHelpers","importHelpers","ignoreDynamic","process","env","SWC_NODE_IGNORE_DYNAMIC","keepClassNames","module","paths","Object","fromEntries","entries","map","aliasKey","aliasPaths","path","react","jsxFactory","jsxFragmentFactory","jsxImportSource","importSource","pragma","pragmaFrag","runtime","JsxEmit","ReactJSX","useBuiltins","sourcemap","sourceMap","inlineSourceMap","swc","inputSourceMap","sourceRoot"],"mappings":"AAEA,SAASA,OAAO,QAAQ,OAAM;AAC9B,OAAOC,QAAQ,aAAY;AAE3B,SAASC,WAAWC,MAAuB;IACzC,OAAQA;QACN,KAAKF,GAAGG,YAAY,CAACC,GA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AG,cAAc;YACnEC,aAAa;QACf,IACA/B;QACNgC,WAAWvC,QAAQwC,SAAS,IAAIxC,QAAQyC,eAAe,GAAG,WAAWrC,QAAQJ,QAAQwC,SAAS;QAC9FE,KAAK;YACHC,gBAAgB3C,QAAQyC,eAAe;YACvCG,YAAY5C,QAAQ4C,UAAU;QAChC;QACA1E,QAAQD,WAAWC;QACnB4B,yBAAyBF,2BAA2BI,SAAS9B;IAC/D;AACF"}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import * as ts from 'typescript';
|
|
2
|
-
export declare function compile(sourcecode: string, filename: string, options: ts.CompilerOptions & {
|
|
3
|
-
fallbackToTs?: (filename: string) => boolean;
|
|
4
|
-
}): string;
|
|
5
|
-
export declare function compile(sourcecode: string, filename: string, options: ts.CompilerOptions & {
|
|
6
|
-
fallbackToTs?: (filename: string) => boolean;
|
|
7
|
-
}, async: false): string;
|
|
8
|
-
export declare function compile(sourcecode: string, filename: string, options: ts.CompilerOptions & {
|
|
9
|
-
fallbackToTs?: (filename: string) => boolean;
|
|
10
|
-
}, async: true): Promise<string>;
|
|
11
|
-
export declare function compile(sourcecode: string, filename: string, options: ts.CompilerOptions & {
|
|
12
|
-
fallbackToTs?: (filename: string) => boolean;
|
|
13
|
-
}, async: boolean): Promise<string> | string;
|
|
14
|
-
export declare function register(options?: Partial<ts.CompilerOptions>, hookOpts?: {}): () => void;
|
|
15
|
-
//# sourceMappingURL=register.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"register.d.ts","sourceRoot":"","sources":["../../../src/bin/register/register.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,MAAM,YAAY,CAAA;AAyBhC,wBAAgB,OAAO,CACrB,UAAU,EAAE,MAAM,EAClB,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,EAAE,CAAC,eAAe,GAAG;IAAE,YAAY,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,OAAO,CAAA;CAAE,GAC7E,MAAM,CAAA;AAET,wBAAgB,OAAO,CACrB,UAAU,EAAE,MAAM,EAClB,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,EAAE,CAAC,eAAe,GAAG;IAAE,YAAY,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,OAAO,CAAA;CAAE,EAC9E,KAAK,EAAE,KAAK,GACX,MAAM,CAAA;AAET,wBAAgB,OAAO,CACrB,UAAU,EAAE,MAAM,EAClB,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,EAAE,CAAC,eAAe,GAAG;IAAE,YAAY,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,OAAO,CAAA;CAAE,EAC9E,KAAK,EAAE,IAAI,GACV,OAAO,CAAC,MAAM,CAAC,CAAA;AAElB,wBAAgB,OAAO,CACrB,UAAU,EAAE,MAAM,EAClB,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,EAAE,CAAC,eAAe,GAAG;IAAE,YAAY,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,OAAO,CAAA;CAAE,EAC9E,KAAK,EAAE,OAAO,GACb,OAAO,CAAC,MAAM,CAAC,GAAG,MAAM,CAAA;AAwD3B,wBAAgB,QAAQ,CAAC,OAAO,GAAE,OAAO,CAAC,EAAE,CAAC,eAAe,CAAM,EAAE,QAAQ,KAAK,cAUhF"}
|
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
import { transform, transformSync } from '@swc-node/core';
|
|
2
|
-
import { SourcemapMap, installSourceMapSupport } from '@swc-node/sourcemap-support';
|
|
3
|
-
import { getTsconfig } from 'get-tsconfig';
|
|
4
|
-
import { platform } from 'os';
|
|
5
|
-
import { resolve } from 'path';
|
|
6
|
-
import { addHook } from 'pirates';
|
|
7
|
-
import * as ts from 'typescript';
|
|
8
|
-
import { tsCompilerOptionsToSwcConfig } from './read-default-tsconfig.js';
|
|
9
|
-
const DEFAULT_EXTENSIONS = [
|
|
10
|
-
'.js',
|
|
11
|
-
'.jsx',
|
|
12
|
-
'.es6',
|
|
13
|
-
'.es',
|
|
14
|
-
'.mjs',
|
|
15
|
-
'.ts',
|
|
16
|
-
'.tsx'
|
|
17
|
-
];
|
|
18
|
-
const PLATFORM = platform();
|
|
19
|
-
const injectInlineSourceMap = ({ code, filename, map })=>{
|
|
20
|
-
if (map) {
|
|
21
|
-
SourcemapMap.set(filename, map);
|
|
22
|
-
const base64Map = Buffer.from(map, 'utf8').toString('base64');
|
|
23
|
-
const sourceMapContent = `//# sourceMappingURL=data:application/json;charset=utf-8;base64,${base64Map}`;
|
|
24
|
-
return `${code}\n${sourceMapContent}`;
|
|
25
|
-
}
|
|
26
|
-
return code;
|
|
27
|
-
};
|
|
28
|
-
export function compile(sourcecode, filename, options, async = false) {
|
|
29
|
-
if (filename.endsWith('.d.ts')) {
|
|
30
|
-
return '';
|
|
31
|
-
}
|
|
32
|
-
if (options.files && options.files.length) {
|
|
33
|
-
if (PLATFORM === 'win32' && options.files.every((file)=>filename !== resolve(process.cwd(), file))) {
|
|
34
|
-
return sourcecode;
|
|
35
|
-
}
|
|
36
|
-
if (PLATFORM !== 'win32' && options.files.every((file)=>!filename.endsWith(file))) {
|
|
37
|
-
return sourcecode;
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
if (options && typeof options.fallbackToTs === 'function' && options.fallbackToTs(filename)) {
|
|
41
|
-
delete options.fallbackToTs;
|
|
42
|
-
const { outputText, sourceMapText } = ts.transpileModule(sourcecode, {
|
|
43
|
-
compilerOptions: options,
|
|
44
|
-
fileName: filename
|
|
45
|
-
});
|
|
46
|
-
return injectInlineSourceMap({
|
|
47
|
-
code: outputText,
|
|
48
|
-
filename,
|
|
49
|
-
map: sourceMapText
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
let swcRegisterConfig;
|
|
53
|
-
if (process.env.SWCRC) {
|
|
54
|
-
// when SWCRC environment variable is set to true it will use swcrc file
|
|
55
|
-
swcRegisterConfig = {
|
|
56
|
-
swc: {
|
|
57
|
-
swcrc: true
|
|
58
|
-
}
|
|
59
|
-
};
|
|
60
|
-
} else {
|
|
61
|
-
swcRegisterConfig = tsCompilerOptionsToSwcConfig(options, filename);
|
|
62
|
-
}
|
|
63
|
-
if (async) {
|
|
64
|
-
return transform(sourcecode, filename, swcRegisterConfig).then(({ code, map })=>{
|
|
65
|
-
return injectInlineSourceMap({
|
|
66
|
-
code,
|
|
67
|
-
filename,
|
|
68
|
-
map
|
|
69
|
-
});
|
|
70
|
-
});
|
|
71
|
-
} else {
|
|
72
|
-
const { code, map } = transformSync(sourcecode, filename, swcRegisterConfig);
|
|
73
|
-
return injectInlineSourceMap({
|
|
74
|
-
code,
|
|
75
|
-
filename,
|
|
76
|
-
map
|
|
77
|
-
});
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
export function register(options = {}, hookOpts = {}) {
|
|
81
|
-
const locatedConfig = getTsconfig();
|
|
82
|
-
const tsconfig = locatedConfig.config.compilerOptions;
|
|
83
|
-
options = tsconfig;
|
|
84
|
-
// options.module = ts.ModuleKind.CommonJS
|
|
85
|
-
installSourceMapSupport();
|
|
86
|
-
return addHook((code, filename)=>compile(code, filename, options), {
|
|
87
|
-
exts: DEFAULT_EXTENSIONS,
|
|
88
|
-
...hookOpts
|
|
89
|
-
});
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
//# sourceMappingURL=register.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/bin/register/register.ts"],"sourcesContent":["import type { Options } from '@swc-node/core'\n\nimport { transform, transformSync } from '@swc-node/core'\nimport { SourcemapMap, installSourceMapSupport } from '@swc-node/sourcemap-support'\nimport { getTsconfig } from 'get-tsconfig'\nimport { platform } from 'os'\nimport { resolve } from 'path'\nimport { addHook } from 'pirates'\nimport * as ts from 'typescript'\n\nimport { tsCompilerOptionsToSwcConfig } from './read-default-tsconfig.js'\n\nconst DEFAULT_EXTENSIONS = ['.js', '.jsx', '.es6', '.es', '.mjs', '.ts', '.tsx']\nconst PLATFORM = platform()\n\nconst injectInlineSourceMap = ({\n code,\n filename,\n map,\n}: {\n code: string\n filename: string\n map: string | undefined\n}): string => {\n if (map) {\n SourcemapMap.set(filename, map)\n const base64Map = Buffer.from(map, 'utf8').toString('base64')\n const sourceMapContent = `//# sourceMappingURL=data:application/json;charset=utf-8;base64,${base64Map}`\n return `${code}\\n${sourceMapContent}`\n }\n return code\n}\n\nexport function compile(\n sourcecode: string,\n filename: string,\n options: ts.CompilerOptions & { fallbackToTs?: (filename: string) => boolean },\n): string\n\nexport function compile(\n sourcecode: string,\n filename: string,\n options: ts.CompilerOptions & { fallbackToTs?: (filename: string) => boolean },\n async: false,\n): string\n\nexport function compile(\n sourcecode: string,\n filename: string,\n options: ts.CompilerOptions & { fallbackToTs?: (filename: string) => boolean },\n async: true,\n): Promise<string>\n\nexport function compile(\n sourcecode: string,\n filename: string,\n options: ts.CompilerOptions & { fallbackToTs?: (filename: string) => boolean },\n async: boolean,\n): Promise<string> | string\n\nexport function compile(\n sourcecode: string,\n filename: string,\n options: ts.CompilerOptions & { fallbackToTs?: (filename: string) => boolean },\n async = false,\n) {\n if (filename.endsWith('.d.ts')) {\n return ''\n }\n if (options.files && (options.files as string[]).length) {\n if (\n PLATFORM === 'win32' &&\n (options.files as string[]).every((file) => filename !== resolve(process.cwd(), file))\n ) {\n return sourcecode\n }\n if (\n PLATFORM !== 'win32' &&\n (options.files as string[]).every((file) => !filename.endsWith(file))\n ) {\n return sourcecode\n }\n }\n if (options && typeof options.fallbackToTs === 'function' && options.fallbackToTs(filename)) {\n delete options.fallbackToTs\n const { outputText, sourceMapText } = ts.transpileModule(sourcecode, {\n compilerOptions: options,\n fileName: filename,\n })\n return injectInlineSourceMap({ code: outputText, filename, map: sourceMapText })\n }\n\n let swcRegisterConfig: Options\n if (process.env.SWCRC) {\n // when SWCRC environment variable is set to true it will use swcrc file\n swcRegisterConfig = {\n swc: {\n swcrc: true,\n },\n }\n } else {\n swcRegisterConfig = tsCompilerOptionsToSwcConfig(options, filename)\n }\n\n if (async) {\n return transform(sourcecode, filename, swcRegisterConfig).then(({ code, map }) => {\n return injectInlineSourceMap({ code, filename, map })\n })\n } else {\n const { code, map } = transformSync(sourcecode, filename, swcRegisterConfig)\n return injectInlineSourceMap({ code, filename, map })\n }\n}\n\nexport function register(options: Partial<ts.CompilerOptions> = {}, hookOpts = {}) {\n const locatedConfig = getTsconfig()\n const tsconfig = locatedConfig.config.compilerOptions as unknown as ts.CompilerOptions\n options = tsconfig\n // options.module = ts.ModuleKind.CommonJS\n installSourceMapSupport()\n return addHook((code, filename) => compile(code, filename, options), {\n exts: DEFAULT_EXTENSIONS,\n ...hookOpts,\n })\n}\n"],"names":["transform","transformSync","SourcemapMap","installSourceMapSupport","getTsconfig","platform","resolve","addHook","ts","tsCompilerOptionsToSwcConfig","DEFAULT_EXTENSIONS","PLATFORM","injectInlineSourceMap","code","filename","map","set","base64Map","Buffer","from","toString","sourceMapContent","compile","sourcecode","options","async","endsWith","files","length","every","file","process","cwd","fallbackToTs","outputText","sourceMapText","transpileModule","compilerOptions","fileName","swcRegisterConfig","env","SWCRC","swc","swcrc","then","register","hookOpts","locatedConfig","tsconfig","config","exts"],"mappings":"AAEA,SAASA,SAAS,EAAEC,aAAa,QAAQ,iBAAgB;AACzD,SAASC,YAAY,EAAEC,uBAAuB,QAAQ,8BAA6B;AACnF,SAASC,WAAW,QAAQ,eAAc;AAC1C,SAASC,QAAQ,QAAQ,KAAI;AAC7B,SAASC,OAAO,QAAQ,OAAM;AAC9B,SAASC,OAAO,QAAQ,UAAS;AACjC,YAAYC,QAAQ,aAAY;AAEhC,SAASC,4BAA4B,QAAQ,6BAA4B;AAEzE,MAAMC,qBAAqB;IAAC;IAAO;IAAQ;IAAQ;IAAO;IAAQ;IAAO;CAAO;AAChF,MAAMC,WAAWN;AAEjB,MAAMO,wBAAwB,CAAC,EAC7BC,IAAI,EACJC,QAAQ,EACRC,GAAG,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,OAAOzB,UAAUuB,YAAYT,UAAUyB,mBAAmBK,IAAI,CAAC,CAAC,EAAE/B,IAAI,EAAEE,GAAG,EAAE;YAC3E,OAAOH,sBAAsB;gBAAEC;gBAAMC;gBAAUC;YAAI;QACrD;IACF,OAAO;QACL,MAAM,EAAEF,IAAI,EAAEE,GAAG,EAAE,GAAGd,cAAcsB,YAAYT,UAAUyB;QAC1D,OAAO3B,sBAAsB;YAAEC;YAAMC;YAAUC;QAAI;IACrD;AACF;AAEA,OAAO,SAAS8B,SAASrB,UAAuC,CAAC,CAAC,EAAEsB,WAAW,CAAC,CAAC;IAC/E,MAAMC,gBAAgB3C;IACtB,MAAM4C,WAAWD,cAAcE,MAAM,CAACZ,eAAe;IACrDb,UAAUwB;IACV,0CAA0C;IAC1C7C;IACA,OAAOI,QAAQ,CAACM,MAAMC,WAAaQ,QAAQT,MAAMC,UAAUU,UAAU;QACnE0B,MAAMxC;QACN,GAAGoC,QAAQ;IACb;AACF"}
|
package/dist/config/load.d.ts
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import type pino from 'pino';
|
|
2
|
-
import type { SanitizedConfig } from './types.js';
|
|
3
|
-
import Logger from '../utilities/logger.js';
|
|
4
|
-
declare const loadConfig: (logger?: pino.Logger) => Promise<SanitizedConfig>;
|
|
5
|
-
export default loadConfig;
|
|
6
|
-
//# sourceMappingURL=load.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"load.d.ts","sourceRoot":"","sources":["../../src/config/load.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,MAAM,CAAA;AAK5B,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AAGjD,OAAO,MAAM,MAAM,wBAAwB,CAAA;AAM3C,QAAA,MAAM,UAAU,YAAmB,WAAW,KAAG,QAAQ,eAAe,CA2BvE,CAAA;AAED,eAAe,UAAU,CAAA"}
|
package/dist/config/load.js
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { createRequire } from 'module';
|
|
2
|
-
import path from 'path';
|
|
3
|
-
import { CLIENT_EXTENSIONS } from '../bin/register/clientExtensions.js';
|
|
4
|
-
import Logger from '../utilities/logger.js';
|
|
5
|
-
import { findConfig } from './find.js';
|
|
6
|
-
import { validateSchema } from './validate.js';
|
|
7
|
-
const require = createRequire(import.meta.url);
|
|
8
|
-
const loadConfig = async (logger)=>{
|
|
9
|
-
const localLogger = logger ?? Logger();
|
|
10
|
-
const configPath = findConfig();
|
|
11
|
-
CLIENT_EXTENSIONS.forEach((ext)=>{
|
|
12
|
-
require.extensions[ext] = ()=>null;
|
|
13
|
-
});
|
|
14
|
-
const configPromise = await import(configPath);
|
|
15
|
-
let config = await configPromise;
|
|
16
|
-
if ('default' in config) config = await config.default;
|
|
17
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
18
|
-
config = validateSchema(config, localLogger);
|
|
19
|
-
}
|
|
20
|
-
return {
|
|
21
|
-
...config,
|
|
22
|
-
paths: {
|
|
23
|
-
config: configPath,
|
|
24
|
-
configDir: path.dirname(configPath),
|
|
25
|
-
rawConfig: configPath
|
|
26
|
-
}
|
|
27
|
-
};
|
|
28
|
-
};
|
|
29
|
-
export default loadConfig;
|
|
30
|
-
|
|
31
|
-
//# sourceMappingURL=load.js.map
|
package/dist/config/load.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/config/load.ts"],"sourcesContent":["import type pino from 'pino'\n\nimport { createRequire } from 'module'\nimport path from 'path'\n\nimport type { SanitizedConfig } from './types.js'\n\nimport { CLIENT_EXTENSIONS } from '../bin/register/clientExtensions.js'\nimport Logger from '../utilities/logger.js'\nimport { findConfig } from './find.js'\nimport { validateSchema } from './validate.js'\n\nconst require = createRequire(import.meta.url)\n\nconst loadConfig = async (logger?: pino.Logger): Promise<SanitizedConfig> => {\n const localLogger = logger ?? Logger()\n\n const configPath = findConfig()\n\n CLIENT_EXTENSIONS.forEach((ext) => {\n require.extensions[ext] = () => null\n })\n\n const configPromise = await import(configPath)\n\n let config = await configPromise\n\n if ('default' in config) config = await config.default\n\n if (process.env.NODE_ENV !== 'production') {\n config = validateSchema(config, localLogger)\n }\n\n return {\n ...config,\n paths: {\n config: configPath,\n configDir: path.dirname(configPath),\n rawConfig: configPath,\n },\n }\n}\n\nexport default loadConfig\n"],"names":["createRequire","path","CLIENT_EXTENSIONS","Logger","findConfig","validateSchema","require","url","loadConfig","logger","localLogger","configPath","forEach","ext","extensions","configPromise","config","default","process","env","NODE_ENV","paths","configDir","dirname","rawConfig"],"mappings":"AAEA,SAASA,aAAa,QAAQ,SAAQ;AACtC,OAAOC,UAAU,OAAM;AAIvB,SAASC,iBAAiB,QAAQ,sCAAqC;AACvE,OAAOC,YAAY,yBAAwB;AAC3C,SAASC,UAAU,QAAQ,YAAW;AACtC,SAASC,cAAc,QAAQ,gBAAe;AAE9C,MAAMC,UAAUN,cAAc,YAAYO,GAAG;AAE7C,MAAMC,aAAa,OAAOC;IACxB,MAAMC,cAAcD,UAAUN;IAE9B,MAAMQ,aAAaP;IAEnBF,kBAAkBU,OAAO,CAAC,CAACC;QACzBP,QAAQQ,UAAU,CAACD,IAAI,GAAG,IAAM;IAClC;IAEA,MAAME,gBAAgB,MAAM,MAAM,CAACJ;IAEnC,IAAIK,SAAS,MAAMD;IAEnB,IAAI,aAAaC,QAAQA,SAAS,MAAMA,OAAOC,OAAO;IAEtD,IAAIC,QAAQC,GAAG,CAACC,QAAQ,KAAK,cAAc;QACzCJ,SAASX,eAAeW,QAAQN;IAClC;IAEA,OAAO;QACL,GAAGM,MAAM;QACTK,OAAO;YACLL,QAAQL;YACRW,WAAWrB,KAAKsB,OAAO,CAACZ;YACxBa,WAAWb;QACb;IACF;AACF;AAEA,eAAeH,WAAU"}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|