create project
This commit is contained in:
13
kitabcitab/node_modules/next/dist/esm/build/swc/index.d.ts
generated
vendored
Normal file
13
kitabcitab/node_modules/next/dist/esm/build/swc/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
export function isWasm(): Promise<boolean>
|
||||
export function transform(src: string, options?: any): Promise<any>
|
||||
export function transformSync(src: string, options?: any): any
|
||||
export function minify(src: string, options: any): Promise<string>
|
||||
export function minifySync(src: string, options: any): string
|
||||
export function parse(src: string, options: any): any
|
||||
export const lockfilePatchPromise: { cur?: Promise<void> }
|
||||
export function initCustomTraceSubscriber(traceFileName?: string): void
|
||||
export function teardownTraceSubscriber(): void
|
||||
export function teardownCrashReporter(): void
|
||||
export function loadBindings(): Promise<void>
|
||||
|
||||
export function __isCustomTurbopackBinary(): Promise<boolean>
|
||||
454
kitabcitab/node_modules/next/dist/esm/build/swc/index.js
generated
vendored
Normal file
454
kitabcitab/node_modules/next/dist/esm/build/swc/index.js
generated
vendored
Normal file
@@ -0,0 +1,454 @@
|
||||
import path from "path";
|
||||
import { pathToFileURL } from "url";
|
||||
import { platform, arch } from "os";
|
||||
import { platformArchTriples } from "next/dist/compiled/@napi-rs/triples";
|
||||
import * as Log from "../output/log";
|
||||
import { getParserOptions } from "./options";
|
||||
import { eventSwcLoadFailure } from "../../telemetry/events/swc-load-failure";
|
||||
import { patchIncorrectLockfile } from "../../lib/patch-incorrect-lockfile";
|
||||
import { downloadWasmSwc } from "../../lib/download-wasm-swc";
|
||||
import { version as nextVersion } from "next/package.json";
|
||||
const ArchName = arch();
|
||||
const PlatformName = platform();
|
||||
const triples = platformArchTriples[PlatformName][ArchName] || [];
|
||||
// Allow to specify an absolute path to the custom turbopack binary to load.
|
||||
// If one of env variables is set, `loadNative` will try to use any turbo-* interfaces from specified
|
||||
// binary instead. This will not affect existing swc's transform, or other interfaces. This is thin,
|
||||
// naive interface - `loadBindings` will not validate neither path nor the binary.
|
||||
//
|
||||
// Note these are internal flag: there's no stability, feature gaurentee.
|
||||
const __INTERNAL_CUSTOM_TURBOPACK_BINARY = process.env.__INTERNAL_CUSTOM_TURBOPACK_BINARY;
|
||||
const __INTERNAL_CUSTOM_TURBOPACK_BINDINGS = process.env.__INTERNAL_CUSTOM_TURBOPACK_BINDINGS;
|
||||
export const __isCustomTurbopackBinary = async ()=>{
|
||||
if (!!__INTERNAL_CUSTOM_TURBOPACK_BINARY && !!__INTERNAL_CUSTOM_TURBOPACK_BINDINGS) {
|
||||
throw new Error("Cannot use TURBOPACK_BINARY and TURBOPACK_BINDINGS both");
|
||||
}
|
||||
return !!__INTERNAL_CUSTOM_TURBOPACK_BINARY || !!__INTERNAL_CUSTOM_TURBOPACK_BINDINGS;
|
||||
};
|
||||
// These are the platforms we'll try to load wasm bindings first,
|
||||
// only try to load native bindings if loading wasm binding somehow fails.
|
||||
// Fallback to native binding is for migration period only,
|
||||
// once we can verify loading-wasm-first won't cause visible regressions,
|
||||
// we'll not include native bindings for these platform at all.
|
||||
const knownDefaultWasmFallbackTriples = [
|
||||
"aarch64-linux-android",
|
||||
"x86_64-unknown-freebsd",
|
||||
"aarch64-pc-windows-msvc",
|
||||
"arm-linux-androideabi",
|
||||
"armv7-unknown-linux-gnueabihf",
|
||||
"i686-pc-windows-msvc",
|
||||
];
|
||||
let nativeBindings;
|
||||
let wasmBindings;
|
||||
let downloadWasmPromise;
|
||||
let pendingBindings;
|
||||
let swcTraceFlushGuard;
|
||||
let swcCrashReporterFlushGuard;
|
||||
export const lockfilePatchPromise = {};
|
||||
export async function loadBindings() {
|
||||
if (pendingBindings) {
|
||||
return pendingBindings;
|
||||
}
|
||||
const isCustomTurbopack = await __isCustomTurbopackBinary();
|
||||
pendingBindings = new Promise(async (resolve, reject)=>{
|
||||
if (!lockfilePatchPromise.cur) {
|
||||
// always run lockfile check once so that it gets patched
|
||||
// even if it doesn't fail to load locally
|
||||
lockfilePatchPromise.cur = patchIncorrectLockfile(process.cwd()).catch(console.error);
|
||||
}
|
||||
let attempts = [];
|
||||
const shouldLoadWasmFallbackFirst = triples.some((triple)=>{
|
||||
return !!(triple == null ? void 0 : triple.raw) && knownDefaultWasmFallbackTriples.includes(triple.raw);
|
||||
});
|
||||
if (shouldLoadWasmFallbackFirst) {
|
||||
const fallbackBindings = await tryLoadWasmWithFallback(attempts);
|
||||
if (fallbackBindings) {
|
||||
return resolve(fallbackBindings);
|
||||
}
|
||||
}
|
||||
try {
|
||||
return resolve(loadNative(isCustomTurbopack));
|
||||
} catch (a) {
|
||||
attempts = attempts.concat(a);
|
||||
}
|
||||
// For these platforms we already tried to load wasm and failed, skip reattempt
|
||||
if (!shouldLoadWasmFallbackFirst) {
|
||||
const fallbackBindings = await tryLoadWasmWithFallback(attempts);
|
||||
if (fallbackBindings) {
|
||||
return resolve(fallbackBindings);
|
||||
}
|
||||
}
|
||||
logLoadFailure(attempts, true);
|
||||
});
|
||||
return pendingBindings;
|
||||
}
|
||||
async function tryLoadWasmWithFallback(attempts) {
|
||||
try {
|
||||
let bindings = await loadWasm();
|
||||
eventSwcLoadFailure({
|
||||
wasm: "enabled"
|
||||
});
|
||||
return bindings;
|
||||
} catch (a) {
|
||||
attempts = attempts.concat(a);
|
||||
}
|
||||
try {
|
||||
// if not installed already download wasm package on-demand
|
||||
// we download to a custom directory instead of to node_modules
|
||||
// as node_module import attempts are cached and can't be re-attempted
|
||||
// x-ref: https://github.com/nodejs/modules/issues/307
|
||||
const wasmDirectory = path.join(path.dirname(require.resolve("next/package.json")), "wasm");
|
||||
if (!downloadWasmPromise) {
|
||||
downloadWasmPromise = downloadWasmSwc(nextVersion, wasmDirectory);
|
||||
}
|
||||
await downloadWasmPromise;
|
||||
let bindings = await loadWasm(pathToFileURL(wasmDirectory).href);
|
||||
eventSwcLoadFailure({
|
||||
wasm: "fallback"
|
||||
});
|
||||
// still log native load attempts so user is
|
||||
// aware it failed and should be fixed
|
||||
for (const attempt of attempts){
|
||||
Log.warn(attempt);
|
||||
}
|
||||
return bindings;
|
||||
} catch (a1) {
|
||||
attempts = attempts.concat(a1);
|
||||
}
|
||||
}
|
||||
function loadBindingsSync() {
|
||||
let attempts = [];
|
||||
try {
|
||||
return loadNative();
|
||||
} catch (a) {
|
||||
attempts = attempts.concat(a);
|
||||
}
|
||||
// we can leverage the wasm bindings if they are already
|
||||
// loaded
|
||||
if (wasmBindings) {
|
||||
return wasmBindings;
|
||||
}
|
||||
logLoadFailure(attempts);
|
||||
}
|
||||
let loggingLoadFailure = false;
|
||||
function logLoadFailure(attempts, triedWasm = false) {
|
||||
// make sure we only emit the event and log the failure once
|
||||
if (loggingLoadFailure) return;
|
||||
loggingLoadFailure = true;
|
||||
for (let attempt of attempts){
|
||||
Log.warn(attempt);
|
||||
}
|
||||
eventSwcLoadFailure({
|
||||
wasm: triedWasm ? "failed" : undefined
|
||||
}).then(()=>lockfilePatchPromise.cur || Promise.resolve()).finally(()=>{
|
||||
Log.error(`Failed to load SWC binary for ${PlatformName}/${ArchName}, see more info here: https://nextjs.org/docs/messages/failed-loading-swc`);
|
||||
process.exit(1);
|
||||
});
|
||||
}
|
||||
async function loadWasm(importPath = "") {
|
||||
if (wasmBindings) {
|
||||
return wasmBindings;
|
||||
}
|
||||
let attempts = [];
|
||||
for (let pkg of [
|
||||
"@next/swc-wasm-nodejs",
|
||||
"@next/swc-wasm-web"
|
||||
]){
|
||||
try {
|
||||
let pkgPath = pkg;
|
||||
if (importPath) {
|
||||
// the import path must be exact when not in node_modules
|
||||
pkgPath = path.join(importPath, pkg, "wasm.js");
|
||||
}
|
||||
let bindings = await import(pkgPath);
|
||||
if (pkg === "@next/swc-wasm-web") {
|
||||
bindings = await bindings.default();
|
||||
}
|
||||
Log.info("Using wasm build of next-swc");
|
||||
// Note wasm binary does not support async intefaces yet, all async
|
||||
// interface coereces to sync interfaces.
|
||||
wasmBindings = {
|
||||
isWasm: true,
|
||||
transform (src, options) {
|
||||
// TODO: we can remove fallback to sync interface once new stable version of next-swc gets published (current v12.2)
|
||||
return (bindings == null ? void 0 : bindings.transform) ? bindings.transform(src.toString(), options) : Promise.resolve(bindings.transformSync(src.toString(), options));
|
||||
},
|
||||
transformSync (src, options) {
|
||||
return bindings.transformSync(src.toString(), options);
|
||||
},
|
||||
minify (src, options) {
|
||||
return (bindings == null ? void 0 : bindings.minify) ? bindings.minify(src.toString(), options) : Promise.resolve(bindings.minifySync(src.toString(), options));
|
||||
},
|
||||
minifySync (src, options) {
|
||||
return bindings.minifySync(src.toString(), options);
|
||||
},
|
||||
parse (src, options) {
|
||||
return (bindings == null ? void 0 : bindings.parse) ? bindings.parse(src.toString(), options) : Promise.resolve(bindings.parseSync(src.toString(), options));
|
||||
},
|
||||
parseSync (src, options) {
|
||||
const astStr = bindings.parseSync(src.toString(), options);
|
||||
return astStr;
|
||||
},
|
||||
getTargetTriple () {
|
||||
return undefined;
|
||||
},
|
||||
turbo: {
|
||||
startDev: ()=>{
|
||||
Log.error("Wasm binding does not support --turbo yet");
|
||||
},
|
||||
startTrace: ()=>{
|
||||
Log.error("Wasm binding does not support trace yet");
|
||||
}
|
||||
},
|
||||
mdx: {
|
||||
compile: (src, options)=>bindings.mdxCompile(src, options),
|
||||
compileSync: (src, options)=>bindings.mdxCompileSync(src, options)
|
||||
}
|
||||
};
|
||||
return wasmBindings;
|
||||
} catch (e) {
|
||||
// Only log attempts for loading wasm when loading as fallback
|
||||
if (importPath) {
|
||||
if ((e == null ? void 0 : e.code) === "ERR_MODULE_NOT_FOUND") {
|
||||
attempts.push(`Attempted to load ${pkg}, but it was not installed`);
|
||||
} else {
|
||||
attempts.push(`Attempted to load ${pkg}, but an error occurred: ${e.message ?? e}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
throw attempts;
|
||||
}
|
||||
function loadNative(isCustomTurbopack = false) {
|
||||
if (nativeBindings) {
|
||||
return nativeBindings;
|
||||
}
|
||||
let bindings;
|
||||
let attempts = [];
|
||||
for (const triple of triples){
|
||||
try {
|
||||
bindings = require(`@next/swc/native/next-swc.${triple.platformArchABI}.node`);
|
||||
Log.info("Using locally built binary of @next/swc");
|
||||
break;
|
||||
} catch (e) {}
|
||||
}
|
||||
if (!bindings) {
|
||||
for (const triple of triples){
|
||||
let pkg = `@next/swc-${triple.platformArchABI}`;
|
||||
try {
|
||||
bindings = require(pkg);
|
||||
break;
|
||||
} catch (e) {
|
||||
if ((e == null ? void 0 : e.code) === "MODULE_NOT_FOUND") {
|
||||
attempts.push(`Attempted to load ${pkg}, but it was not installed`);
|
||||
} else {
|
||||
attempts.push(`Attempted to load ${pkg}, but an error occurred: ${e.message ?? e}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (bindings) {
|
||||
// Initialize crash reporter, as earliest as possible from any point of import.
|
||||
// The first-time import to next-swc is not predicatble in the import tree of next.js, which makes
|
||||
// we can't rely on explicit manual initialization as similar to trace reporter.
|
||||
if (!swcCrashReporterFlushGuard) {
|
||||
// Crash reports in next-swc should be treated in the same way we treat telemetry to opt out.
|
||||
/* TODO: temporarily disable initialization while confirming logistics.
|
||||
let telemetry = new Telemetry({ distDir: process.cwd() })
|
||||
if (telemetry.isEnabled) {
|
||||
swcCrashReporterFlushGuard = bindings.initCrashReporter?.()
|
||||
}*/ }
|
||||
nativeBindings = {
|
||||
isWasm: false,
|
||||
transform (src, options) {
|
||||
var ref;
|
||||
const isModule = typeof src !== undefined && typeof src !== "string" && !Buffer.isBuffer(src);
|
||||
options = options || {};
|
||||
if (options == null ? void 0 : (ref = options.jsc) == null ? void 0 : ref.parser) {
|
||||
options.jsc.parser.syntax = options.jsc.parser.syntax ?? "ecmascript";
|
||||
}
|
||||
return bindings.transform(isModule ? JSON.stringify(src) : src, isModule, toBuffer(options));
|
||||
},
|
||||
transformSync (src, options) {
|
||||
var ref;
|
||||
if (typeof src === undefined) {
|
||||
throw new Error("transformSync doesn't implement reading the file from filesystem");
|
||||
} else if (Buffer.isBuffer(src)) {
|
||||
throw new Error("transformSync doesn't implement taking the source code as Buffer");
|
||||
}
|
||||
const isModule = typeof src !== "string";
|
||||
options = options || {};
|
||||
if (options == null ? void 0 : (ref = options.jsc) == null ? void 0 : ref.parser) {
|
||||
options.jsc.parser.syntax = options.jsc.parser.syntax ?? "ecmascript";
|
||||
}
|
||||
return bindings.transformSync(isModule ? JSON.stringify(src) : src, isModule, toBuffer(options));
|
||||
},
|
||||
minify (src, options) {
|
||||
return bindings.minify(toBuffer(src), toBuffer(options ?? {}));
|
||||
},
|
||||
minifySync (src, options) {
|
||||
return bindings.minifySync(toBuffer(src), toBuffer(options ?? {}));
|
||||
},
|
||||
parse (src, options) {
|
||||
return bindings.parse(src, toBuffer(options ?? {}));
|
||||
},
|
||||
getTargetTriple: bindings.getTargetTriple,
|
||||
initCustomTraceSubscriber: bindings.initCustomTraceSubscriber,
|
||||
teardownTraceSubscriber: bindings.teardownTraceSubscriber,
|
||||
teardownCrashReporter: bindings.teardownCrashReporter,
|
||||
turbo: {
|
||||
startDev: (options)=>{
|
||||
const devOptions = {
|
||||
...options,
|
||||
noOpen: options.noOpen ?? true
|
||||
};
|
||||
if (!isCustomTurbopack) {
|
||||
bindings.startTurboDev(toBuffer(devOptions));
|
||||
} else if (!!__INTERNAL_CUSTOM_TURBOPACK_BINARY) {
|
||||
console.warn(`Loading custom turbopack binary from ${__INTERNAL_CUSTOM_TURBOPACK_BINARY}`);
|
||||
return new Promise((resolve, reject)=>{
|
||||
const spawn = require("next/dist/compiled/cross-spawn");
|
||||
const args = [];
|
||||
Object.entries(devOptions).forEach(([key, value])=>{
|
||||
let cli_key = `--${key.replace(/[A-Z]/g, (m)=>"-" + m.toLowerCase())}`;
|
||||
if (key === "dir") {
|
||||
args.push(value);
|
||||
} else if (typeof value === "boolean" && value === true) {
|
||||
args.push(cli_key);
|
||||
} else if (typeof value !== "boolean" && !!value) {
|
||||
args.push(cli_key, value);
|
||||
}
|
||||
});
|
||||
console.warn(`Running turbopack with args: [${args.join(" ")}]`);
|
||||
const child = spawn(__INTERNAL_CUSTOM_TURBOPACK_BINARY, args, {
|
||||
stdio: "inherit",
|
||||
env: {
|
||||
...process.env
|
||||
}
|
||||
});
|
||||
child.on("message", (message)=>{
|
||||
console.log(message);
|
||||
});
|
||||
child.on("close", (code)=>{
|
||||
if (code !== 0) {
|
||||
reject({
|
||||
command: `${__INTERNAL_CUSTOM_TURBOPACK_BINARY} ${args.join(" ")}`
|
||||
});
|
||||
return;
|
||||
}
|
||||
resolve(0);
|
||||
});
|
||||
});
|
||||
} else if (!!__INTERNAL_CUSTOM_TURBOPACK_BINDINGS) {
|
||||
console.warn(`Loading custom turbopack bindings from ${__INTERNAL_CUSTOM_TURBOPACK_BINARY}`);
|
||||
console.warn(`Running turbopack with args: `, devOptions);
|
||||
require(__INTERNAL_CUSTOM_TURBOPACK_BINDINGS).startDev(devOptions);
|
||||
}
|
||||
},
|
||||
startTrace: (options = {})=>bindings.runTurboTracing(toBuffer({
|
||||
exact: true,
|
||||
...options
|
||||
}))
|
||||
},
|
||||
mdx: {
|
||||
compile: (src, options)=>bindings.mdxCompile(src, toBuffer(options ?? {})),
|
||||
compileSync: (src, options)=>bindings.mdxCompileSync(src, toBuffer(options ?? {}))
|
||||
}
|
||||
};
|
||||
return nativeBindings;
|
||||
}
|
||||
throw attempts;
|
||||
}
|
||||
function toBuffer(t) {
|
||||
return Buffer.from(JSON.stringify(t));
|
||||
}
|
||||
export async function isWasm() {
|
||||
let bindings = await loadBindings();
|
||||
return bindings.isWasm;
|
||||
}
|
||||
export async function transform(src, options) {
|
||||
let bindings = await loadBindings();
|
||||
return bindings.transform(src, options);
|
||||
}
|
||||
export function transformSync(src, options) {
|
||||
let bindings = loadBindingsSync();
|
||||
return bindings.transformSync(src, options);
|
||||
}
|
||||
export async function minify(src, options) {
|
||||
let bindings = await loadBindings();
|
||||
return bindings.minify(src, options);
|
||||
}
|
||||
export function minifySync(src, options) {
|
||||
let bindings = loadBindingsSync();
|
||||
return bindings.minifySync(src, options);
|
||||
}
|
||||
export async function parse(src, options) {
|
||||
let bindings = await loadBindings();
|
||||
let parserOptions = getParserOptions(options);
|
||||
return bindings.parse(src, parserOptions).then((astStr)=>JSON.parse(astStr));
|
||||
}
|
||||
export function getBinaryMetadata() {
|
||||
let bindings;
|
||||
try {
|
||||
bindings = loadNative();
|
||||
} catch (e) {
|
||||
// Suppress exceptions, this fn allows to fail to load native bindings
|
||||
}
|
||||
return {
|
||||
target: bindings == null ? void 0 : bindings.getTargetTriple == null ? void 0 : bindings.getTargetTriple()
|
||||
};
|
||||
}
|
||||
/**
|
||||
* Initialize trace subscriber to emit traces.
|
||||
*
|
||||
*/ export const initCustomTraceSubscriber = (()=>{
|
||||
return (filename)=>{
|
||||
if (!swcTraceFlushGuard) {
|
||||
// Wasm binary doesn't support trace emission
|
||||
let bindings = loadNative();
|
||||
swcTraceFlushGuard = bindings.initCustomTraceSubscriber(filename);
|
||||
}
|
||||
};
|
||||
})();
|
||||
/**
|
||||
* Teardown swc's trace subscriber if there's an initialized flush guard exists.
|
||||
*
|
||||
* This is workaround to amend behavior with process.exit
|
||||
* (https://github.com/vercel/next.js/blob/4db8c49cc31e4fc182391fae6903fb5ef4e8c66e/packages/next/bin/next.ts#L134=)
|
||||
* seems preventing napi's cleanup hook execution (https://github.com/swc-project/swc/blob/main/crates/node/src/util.rs#L48-L51=),
|
||||
*
|
||||
* instead parent process manually drops guard when process gets signal to exit.
|
||||
*/ export const teardownTraceSubscriber = (()=>{
|
||||
let flushed = false;
|
||||
return ()=>{
|
||||
if (!flushed) {
|
||||
flushed = true;
|
||||
try {
|
||||
let bindings = loadNative();
|
||||
if (swcTraceFlushGuard) {
|
||||
bindings.teardownTraceSubscriber(swcTraceFlushGuard);
|
||||
}
|
||||
} catch (e) {
|
||||
// Suppress exceptions, this fn allows to fail to load native bindings
|
||||
}
|
||||
}
|
||||
};
|
||||
})();
|
||||
export const teardownCrashReporter = (()=>{
|
||||
let flushed = false;
|
||||
return ()=>{
|
||||
if (!flushed) {
|
||||
flushed = true;
|
||||
try {
|
||||
let bindings = loadNative();
|
||||
if (swcCrashReporterFlushGuard) {
|
||||
bindings.teardownCrashReporter(swcCrashReporterFlushGuard);
|
||||
}
|
||||
} catch (e) {
|
||||
// Suppress exceptions, this fn allows to fail to load native bindings
|
||||
}
|
||||
}
|
||||
};
|
||||
})();
|
||||
|
||||
//# sourceMappingURL=index.js.map
|
||||
1
kitabcitab/node_modules/next/dist/esm/build/swc/index.js.map
generated
vendored
Normal file
1
kitabcitab/node_modules/next/dist/esm/build/swc/index.js.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
63
kitabcitab/node_modules/next/dist/esm/build/swc/jest-transformer.js
generated
vendored
Normal file
63
kitabcitab/node_modules/next/dist/esm/build/swc/jest-transformer.js
generated
vendored
Normal file
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
Copyright (c) 2021 The swc Project Developers
|
||||
|
||||
Permission is hereby granted, free of charge, to any
|
||||
person obtaining a copy of this software and associated
|
||||
documentation files (the "Software"), to deal in the
|
||||
Software without restriction, including without
|
||||
limitation the rights to use, copy, modify, merge,
|
||||
publish, distribute, sublicense, and/or sell copies of
|
||||
the Software, and to permit persons to whom the Software
|
||||
is furnished to do so, subject to the following
|
||||
conditions:
|
||||
|
||||
The above copyright notice and this permission notice
|
||||
shall be included in all copies or substantial portions
|
||||
of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
|
||||
ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
|
||||
TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
|
||||
PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
|
||||
SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||||
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
|
||||
IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
DEALINGS IN THE SOFTWARE.
|
||||
*/ import vm from "vm";
|
||||
import { transformSync } from "./index";
|
||||
import { getJestSWCOptions } from "./options";
|
||||
// Jest use the `vm` [Module API](https://nodejs.org/api/vm.html#vm_class_vm_module) for ESM.
|
||||
// see https://github.com/facebook/jest/issues/9430
|
||||
const isSupportEsm = "Module" in vm;
|
||||
module.exports = {
|
||||
createTransformer: (inputOptions)=>({
|
||||
process (src, filename, jestOptions) {
|
||||
const jestConfig = getJestConfig(jestOptions);
|
||||
let swcTransformOpts = getJestSWCOptions({
|
||||
// When target is node it's similar to the server option set in SWC.
|
||||
isServer: jestConfig.testEnvironment && jestConfig.testEnvironment === "node",
|
||||
filename,
|
||||
nextConfig: inputOptions.nextConfig,
|
||||
jsConfig: inputOptions.jsConfig,
|
||||
resolvedBaseUrl: inputOptions.resolvedBaseUrl,
|
||||
pagesDir: inputOptions.pagesDir,
|
||||
hasServerComponents: inputOptions.hasServerComponents,
|
||||
esm: isSupportEsm && isEsm(Boolean(inputOptions.isEsmProject), filename, jestConfig)
|
||||
});
|
||||
return transformSync(src, {
|
||||
...swcTransformOpts,
|
||||
filename
|
||||
});
|
||||
}
|
||||
})
|
||||
};
|
||||
function getJestConfig(jestConfig) {
|
||||
return "config" in jestConfig ? jestConfig.config : jestConfig;
|
||||
}
|
||||
function isEsm(isEsmProject, filename, jestConfig) {
|
||||
var ref;
|
||||
return /\.jsx?$/.test(filename) && isEsmProject || ((ref = jestConfig.extensionsToTreatAsEsm) == null ? void 0 : ref.find((ext)=>filename.endsWith(ext)));
|
||||
}
|
||||
|
||||
//# sourceMappingURL=jest-transformer.js.map
|
||||
1
kitabcitab/node_modules/next/dist/esm/build/swc/jest-transformer.js.map
generated
vendored
Normal file
1
kitabcitab/node_modules/next/dist/esm/build/swc/jest-transformer.js.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"sources":["../../../build/swc/jest-transformer.js"],"names":["vm","transformSync","getJestSWCOptions","isSupportEsm","module","exports","createTransformer","inputOptions","process","src","filename","jestOptions","jestConfig","getJestConfig","swcTransformOpts","isServer","testEnvironment","nextConfig","jsConfig","resolvedBaseUrl","pagesDir","hasServerComponents","esm","isEsm","Boolean","isEsmProject","config","test","extensionsToTreatAsEsm","find","ext","endsWith"],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;EA0BE,CAEF,OAAOA,EAAE,MAAM,IAAI,CAAA;AACnB,SAASC,aAAa,QAAQ,SAAS,CAAA;AACvC,SAASC,iBAAiB,QAAQ,WAAW,CAAA;AAE7C,6FAA6F;AAC7F,mDAAmD;AACnD,MAAMC,YAAY,GAAG,QAAQ,IAAIH,EAAE;AAEnCI,MAAM,CAACC,OAAO,GAAG;IACfC,iBAAiB,EAAE,CAACC,YAAY,GAAK,CAAC;YACpCC,OAAO,EAACC,GAAG,EAAEC,QAAQ,EAAEC,WAAW,EAAE;gBAClC,MAAMC,UAAU,GAAGC,aAAa,CAACF,WAAW,CAAC;gBAE7C,IAAIG,gBAAgB,GAAGZ,iBAAiB,CAAC;oBACvC,oEAAoE;oBACpEa,QAAQ,EACNH,UAAU,CAACI,eAAe,IAAIJ,UAAU,CAACI,eAAe,KAAK,MAAM;oBACrEN,QAAQ;oBACRO,UAAU,EAAEV,YAAY,CAACU,UAAU;oBACnCC,QAAQ,EAAEX,YAAY,CAACW,QAAQ;oBAC/BC,eAAe,EAAEZ,YAAY,CAACY,eAAe;oBAC7CC,QAAQ,EAAEb,YAAY,CAACa,QAAQ;oBAC/BC,mBAAmB,EAAEd,YAAY,CAACc,mBAAmB;oBACrDC,GAAG,EACDnB,YAAY,IACZoB,KAAK,CAACC,OAAO,CAACjB,YAAY,CAACkB,YAAY,CAAC,EAAEf,QAAQ,EAAEE,UAAU,CAAC;iBAClE,CAAC;gBAEF,OAAOX,aAAa,CAACQ,GAAG,EAAE;oBAAE,GAAGK,gBAAgB;oBAAEJ,QAAQ;iBAAE,CAAC,CAAA;aAC7D;SACF,CAAC;CACH;AAED,SAASG,aAAa,CAACD,UAAU,EAAE;IACjC,OAAO,QAAQ,IAAIA,UAAU,GAEzBA,UAAU,CAACc,MAAM,GAEjBd,UAAU,CAAA;CACf;AAED,SAASW,KAAK,CAACE,YAAY,EAAEf,QAAQ,EAAEE,UAAU,EAAE;QAG/CA,GAAiC;IAFnC,OACE,AAAC,UAAUe,IAAI,CAACjB,QAAQ,CAAC,IAAIe,YAAY,KACzCb,CAAAA,GAAiC,GAAjCA,UAAU,CAACgB,sBAAsB,SAAM,GAAvChB,KAAAA,CAAuC,GAAvCA,GAAiC,CAAEiB,IAAI,CAAC,CAACC,GAAG,GAAKpB,QAAQ,CAACqB,QAAQ,CAACD,GAAG,CAAC,CAAC,CAAA,CACzE;CACF"}
|
||||
7
kitabcitab/node_modules/next/dist/esm/build/swc/options.d.ts
generated
vendored
Normal file
7
kitabcitab/node_modules/next/dist/esm/build/swc/options.d.ts
generated
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
export function getParserOptions(options: {
|
||||
filename: string
|
||||
jsConfig?: any
|
||||
[key: string]: any
|
||||
}): any
|
||||
export function getJestSWCOptions(...args: any[]): any
|
||||
export function getLoaderSWCOptions(...args: any[]): any
|
||||
229
kitabcitab/node_modules/next/dist/esm/build/swc/options.js
generated
vendored
Normal file
229
kitabcitab/node_modules/next/dist/esm/build/swc/options.js
generated
vendored
Normal file
@@ -0,0 +1,229 @@
|
||||
const nextDistPath = /(next[\\/]dist[\\/]shared[\\/]lib)|(next[\\/]dist[\\/]client)|(next[\\/]dist[\\/]pages)/;
|
||||
const regeneratorRuntimePath = require.resolve("next/dist/compiled/regenerator-runtime");
|
||||
export function getParserOptions({ filename , jsConfig , ...rest }) {
|
||||
var ref;
|
||||
const isTSFile = filename.endsWith(".ts");
|
||||
const isTypeScript = isTSFile || filename.endsWith(".tsx");
|
||||
const enableDecorators = Boolean(jsConfig == null ? void 0 : (ref = jsConfig.compilerOptions) == null ? void 0 : ref.experimentalDecorators);
|
||||
return {
|
||||
...rest,
|
||||
syntax: isTypeScript ? "typescript" : "ecmascript",
|
||||
dynamicImport: true,
|
||||
decorators: enableDecorators,
|
||||
// Exclude regular TypeScript files from React transformation to prevent e.g. generic parameters and angle-bracket type assertion from being interpreted as JSX tags.
|
||||
[isTypeScript ? "tsx" : "jsx"]: !isTSFile,
|
||||
importAssertions: true
|
||||
};
|
||||
}
|
||||
function getBaseSWCOptions({ filename , jest , development , hasReactRefresh , globalWindow , nextConfig , resolvedBaseUrl , jsConfig , swcCacheDir , isServerLayer , hasServerComponents , }) {
|
||||
var ref, ref1, ref2, ref3, ref4, ref5, ref6, ref7, ref8, ref9;
|
||||
const parserConfig = getParserOptions({
|
||||
filename,
|
||||
jsConfig
|
||||
});
|
||||
const paths = jsConfig == null ? void 0 : (ref = jsConfig.compilerOptions) == null ? void 0 : ref.paths;
|
||||
const enableDecorators = Boolean(jsConfig == null ? void 0 : (ref1 = jsConfig.compilerOptions) == null ? void 0 : ref1.experimentalDecorators);
|
||||
const emitDecoratorMetadata = Boolean(jsConfig == null ? void 0 : (ref2 = jsConfig.compilerOptions) == null ? void 0 : ref2.emitDecoratorMetadata);
|
||||
const useDefineForClassFields = Boolean(jsConfig == null ? void 0 : (ref3 = jsConfig.compilerOptions) == null ? void 0 : ref3.useDefineForClassFields);
|
||||
const plugins = ((nextConfig == null ? void 0 : (ref4 = nextConfig.experimental) == null ? void 0 : ref4.swcPlugins) ?? []).filter(Array.isArray).map(([name, options])=>[
|
||||
require.resolve(name),
|
||||
options
|
||||
]);
|
||||
return {
|
||||
jsc: {
|
||||
...resolvedBaseUrl && paths ? {
|
||||
baseUrl: resolvedBaseUrl,
|
||||
paths
|
||||
} : {},
|
||||
externalHelpers: !process.versions.pnp && !jest,
|
||||
parser: parserConfig,
|
||||
experimental: {
|
||||
keepImportAssertions: true,
|
||||
plugins,
|
||||
cacheRoot: swcCacheDir
|
||||
},
|
||||
transform: {
|
||||
// Enables https://github.com/swc-project/swc/blob/0359deb4841be743d73db4536d4a22ac797d7f65/crates/swc_ecma_ext_transforms/src/jest.rs
|
||||
...jest ? {
|
||||
hidden: {
|
||||
jest: true
|
||||
}
|
||||
} : {},
|
||||
legacyDecorator: enableDecorators,
|
||||
decoratorMetadata: emitDecoratorMetadata,
|
||||
useDefineForClassFields: useDefineForClassFields,
|
||||
react: {
|
||||
importSource: (jsConfig == null ? void 0 : (ref5 = jsConfig.compilerOptions) == null ? void 0 : ref5.jsxImportSource) ?? ((nextConfig == null ? void 0 : (ref6 = nextConfig.compiler) == null ? void 0 : ref6.emotion) ? "@emotion/react" : "react"),
|
||||
runtime: "automatic",
|
||||
pragma: "React.createElement",
|
||||
pragmaFrag: "React.Fragment",
|
||||
throwIfNamespace: true,
|
||||
development: !!development,
|
||||
useBuiltins: true,
|
||||
refresh: !!hasReactRefresh
|
||||
},
|
||||
optimizer: {
|
||||
simplify: false,
|
||||
globals: jest ? null : {
|
||||
typeofs: {
|
||||
window: globalWindow ? "object" : "undefined"
|
||||
},
|
||||
envs: {
|
||||
NODE_ENV: development ? '"development"' : '"production"'
|
||||
}
|
||||
}
|
||||
},
|
||||
regenerator: {
|
||||
importPath: regeneratorRuntimePath
|
||||
}
|
||||
}
|
||||
},
|
||||
sourceMaps: jest ? "inline" : undefined,
|
||||
removeConsole: nextConfig == null ? void 0 : (ref7 = nextConfig.compiler) == null ? void 0 : ref7.removeConsole,
|
||||
// disable "reactRemoveProperties" when "jest" is true
|
||||
// otherwise the setting from next.config.js will be used
|
||||
reactRemoveProperties: jest ? false : nextConfig == null ? void 0 : (ref8 = nextConfig.compiler) == null ? void 0 : ref8.reactRemoveProperties,
|
||||
modularizeImports: nextConfig == null ? void 0 : nextConfig.modularizeImports,
|
||||
relay: nextConfig == null ? void 0 : (ref9 = nextConfig.compiler) == null ? void 0 : ref9.relay,
|
||||
// Always transform styled-jsx and error when `client-only` condition is triggered
|
||||
styledJsx: true,
|
||||
// Disable css-in-js libs (without client-only integration) transform on server layer for server components
|
||||
...!isServerLayer && {
|
||||
emotion: getEmotionOptions(nextConfig, development),
|
||||
styledComponents: getStyledComponentsOptions(nextConfig, development)
|
||||
},
|
||||
serverComponents: hasServerComponents ? {
|
||||
isServer: !!isServerLayer
|
||||
} : undefined
|
||||
};
|
||||
}
|
||||
function getStyledComponentsOptions(nextConfig, development) {
|
||||
var ref;
|
||||
let styledComponentsOptions = nextConfig == null ? void 0 : (ref = nextConfig.compiler) == null ? void 0 : ref.styledComponents;
|
||||
if (!styledComponentsOptions) {
|
||||
return null;
|
||||
}
|
||||
return {
|
||||
...styledComponentsOptions,
|
||||
displayName: styledComponentsOptions.displayName ?? Boolean(development)
|
||||
};
|
||||
}
|
||||
function getEmotionOptions(nextConfig, development) {
|
||||
var ref, ref10, ref11, ref12, ref13, ref14, ref15, ref16, ref17;
|
||||
if (!(nextConfig == null ? void 0 : (ref = nextConfig.compiler) == null ? void 0 : ref.emotion)) {
|
||||
return null;
|
||||
}
|
||||
let autoLabel = false;
|
||||
switch(nextConfig == null ? void 0 : (ref10 = nextConfig.compiler) == null ? void 0 : (ref11 = ref10.emotion) == null ? void 0 : ref11.autoLabel){
|
||||
case "never":
|
||||
autoLabel = false;
|
||||
break;
|
||||
case "always":
|
||||
autoLabel = true;
|
||||
break;
|
||||
case "dev-only":
|
||||
default:
|
||||
autoLabel = !!development;
|
||||
break;
|
||||
}
|
||||
return {
|
||||
enabled: true,
|
||||
autoLabel,
|
||||
importMap: nextConfig == null ? void 0 : (ref12 = nextConfig.compiler) == null ? void 0 : (ref13 = ref12.emotion) == null ? void 0 : ref13.importMap,
|
||||
labelFormat: nextConfig == null ? void 0 : (ref14 = nextConfig.compiler) == null ? void 0 : (ref15 = ref14.emotion) == null ? void 0 : ref15.labelFormat,
|
||||
sourcemap: development ? (nextConfig == null ? void 0 : (ref16 = nextConfig.compiler) == null ? void 0 : (ref17 = ref16.emotion) == null ? void 0 : ref17.sourceMap) ?? true : false
|
||||
};
|
||||
}
|
||||
export function getJestSWCOptions({ isServer , filename , esm , nextConfig , jsConfig , pagesDir , hasServerComponents , }) {
|
||||
let baseOptions = getBaseSWCOptions({
|
||||
filename,
|
||||
jest: true,
|
||||
development: false,
|
||||
hasReactRefresh: false,
|
||||
globalWindow: !isServer,
|
||||
nextConfig,
|
||||
jsConfig,
|
||||
hasServerComponents
|
||||
});
|
||||
const isNextDist = nextDistPath.test(filename);
|
||||
return {
|
||||
...baseOptions,
|
||||
env: {
|
||||
targets: {
|
||||
// Targets the current version of Node.js
|
||||
node: process.versions.node
|
||||
}
|
||||
},
|
||||
module: {
|
||||
type: esm && !isNextDist ? "es6" : "commonjs"
|
||||
},
|
||||
disableNextSsg: true,
|
||||
disablePageConfig: true,
|
||||
pagesDir
|
||||
};
|
||||
}
|
||||
export function getLoaderSWCOptions({ filename , development , isServer , isServerLayer , pagesDir , isPageFile , hasReactRefresh , nextConfig , jsConfig , supportedBrowsers , swcCacheDir , relativeFilePathFromRoot , hasServerComponents , }) {
|
||||
var ref;
|
||||
let baseOptions = getBaseSWCOptions({
|
||||
filename,
|
||||
development,
|
||||
globalWindow: !isServer,
|
||||
hasReactRefresh,
|
||||
nextConfig,
|
||||
jsConfig,
|
||||
// resolvedBaseUrl,
|
||||
swcCacheDir,
|
||||
isServerLayer,
|
||||
relativeFilePathFromRoot,
|
||||
hasServerComponents
|
||||
});
|
||||
if ((nextConfig == null ? void 0 : (ref = nextConfig.experimental) == null ? void 0 : ref.fontLoaders) && relativeFilePathFromRoot) {
|
||||
baseOptions.fontLoaders = {
|
||||
fontLoaders: nextConfig.experimental.fontLoaders.map(({ loader })=>loader),
|
||||
relativeFilePathFromRoot
|
||||
};
|
||||
}
|
||||
const isNextDist = nextDistPath.test(filename);
|
||||
if (isServer) {
|
||||
return {
|
||||
...baseOptions,
|
||||
// Disables getStaticProps/getServerSideProps tree shaking on the server compilation for pages
|
||||
disableNextSsg: true,
|
||||
disablePageConfig: true,
|
||||
isDevelopment: development,
|
||||
isServer,
|
||||
pagesDir,
|
||||
isPageFile,
|
||||
env: {
|
||||
targets: {
|
||||
// Targets the current version of Node.js
|
||||
node: process.versions.node
|
||||
}
|
||||
}
|
||||
};
|
||||
} else {
|
||||
// Matches default @babel/preset-env behavior
|
||||
baseOptions.jsc.target = "es5";
|
||||
return {
|
||||
...baseOptions,
|
||||
// Ensure Next.js internals are output as commonjs modules
|
||||
...isNextDist ? {
|
||||
module: {
|
||||
type: "commonjs"
|
||||
}
|
||||
} : {},
|
||||
disableNextSsg: !isPageFile,
|
||||
isDevelopment: development,
|
||||
isServer,
|
||||
pagesDir,
|
||||
isPageFile,
|
||||
...supportedBrowsers && supportedBrowsers.length > 0 ? {
|
||||
env: {
|
||||
targets: supportedBrowsers
|
||||
}
|
||||
} : {}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
//# sourceMappingURL=options.js.map
|
||||
1
kitabcitab/node_modules/next/dist/esm/build/swc/options.js.map
generated
vendored
Normal file
1
kitabcitab/node_modules/next/dist/esm/build/swc/options.js.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user