Initial boiler plate project
This commit is contained in:
1
node_modules/next/dist/build/swc/helpers.d.ts
generated
vendored
Normal file
1
node_modules/next/dist/build/swc/helpers.d.ts
generated
vendored
Normal file
@ -0,0 +1 @@
|
||||
export declare function __nextjs_pure<T>(expr: T): T;
|
||||
15
node_modules/next/dist/build/swc/helpers.js
generated
vendored
Normal file
15
node_modules/next/dist/build/swc/helpers.js
generated
vendored
Normal file
@ -0,0 +1,15 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
Object.defineProperty(exports, "__nextjs_pure", {
|
||||
enumerable: true,
|
||||
get: function() {
|
||||
return __nextjs_pure;
|
||||
}
|
||||
});
|
||||
function __nextjs_pure(expr) {
|
||||
return expr;
|
||||
}
|
||||
|
||||
//# sourceMappingURL=helpers.js.map
|
||||
1
node_modules/next/dist/build/swc/helpers.js.map
generated
vendored
Normal file
1
node_modules/next/dist/build/swc/helpers.js.map
generated
vendored
Normal file
@ -0,0 +1 @@
|
||||
{"version":3,"sources":["../../../src/build/swc/helpers.ts"],"names":["__nextjs_pure","expr"],"mappings":";;;;+BAAgBA;;;eAAAA;;;AAAT,SAASA,cAAiBC,IAAO;IACtC,OAAOA;AACT"}
|
||||
349
node_modules/next/dist/build/swc/index.d.ts
generated
vendored
Normal file
349
node_modules/next/dist/build/swc/index.d.ts
generated
vendored
Normal file
@ -0,0 +1,349 @@
|
||||
import type { NextConfigComplete } from '../../server/config-shared';
|
||||
import type { DefineEnvPluginOptions } from '../webpack/plugins/define-env-plugin';
|
||||
import type { __ApiPreviewProps } from '../../server/api-utils';
|
||||
/**
|
||||
* Based on napi-rs's target triples, returns triples that have corresponding next-swc binaries.
|
||||
*/
|
||||
export declare const getSupportedArchTriples: () => Record<string, any>;
|
||||
export declare const lockfilePatchPromise: {
|
||||
cur?: Promise<void>;
|
||||
};
|
||||
export interface Binding {
|
||||
isWasm: boolean;
|
||||
turbo: {
|
||||
startTrace: any;
|
||||
nextBuild?: any;
|
||||
createTurboTasks?: any;
|
||||
entrypoints: {
|
||||
stream: any;
|
||||
get: any;
|
||||
};
|
||||
mdx: {
|
||||
compile: any;
|
||||
compileSync: any;
|
||||
};
|
||||
createProject: (options: ProjectOptions, turboEngineOptions?: TurboEngineOptions) => Promise<Project>;
|
||||
};
|
||||
minify: any;
|
||||
minifySync: any;
|
||||
transform: any;
|
||||
transformSync: any;
|
||||
parse: any;
|
||||
parseSync: any;
|
||||
getTargetTriple(): string | undefined;
|
||||
initCustomTraceSubscriber?: any;
|
||||
teardownTraceSubscriber?: any;
|
||||
initHeapProfiler?: any;
|
||||
teardownHeapProfiler?: any;
|
||||
css: {
|
||||
lightning: {
|
||||
transform(transformOptions: any): Promise<any>;
|
||||
transformStyleAttr(attrOptions: any): Promise<any>;
|
||||
};
|
||||
};
|
||||
}
|
||||
export declare function loadBindings(useWasmBinary?: boolean): Promise<Binding>;
|
||||
export interface ProjectOptions {
|
||||
/**
|
||||
* A root path from which all files must be nested under. Trying to access
|
||||
* a file outside this root will fail. Think of this as a chroot.
|
||||
*/
|
||||
rootPath: string;
|
||||
/**
|
||||
* A path inside the root_path which contains the app/pages directories.
|
||||
*/
|
||||
projectPath: string;
|
||||
/**
|
||||
* The next.config.js contents.
|
||||
*/
|
||||
nextConfig: NextConfigComplete;
|
||||
/**
|
||||
* Jsconfig, or tsconfig contents.
|
||||
*
|
||||
* Next.js implicitly requires to read it to support few options
|
||||
* https://nextjs.org/docs/architecture/nextjs-compiler#legacy-decorators
|
||||
* https://nextjs.org/docs/architecture/nextjs-compiler#importsource
|
||||
*/
|
||||
jsConfig: {
|
||||
compilerOptions: object;
|
||||
};
|
||||
/**
|
||||
* A map of environment variables to use when compiling code.
|
||||
*/
|
||||
env: Record<string, string>;
|
||||
defineEnv: DefineEnv;
|
||||
/**
|
||||
* Whether to watch the filesystem for file changes.
|
||||
*/
|
||||
watch: boolean;
|
||||
/**
|
||||
* The mode in which Next.js is running.
|
||||
*/
|
||||
dev: boolean;
|
||||
/**
|
||||
* The server actions encryption key.
|
||||
*/
|
||||
encryptionKey: string;
|
||||
/**
|
||||
* The build id.
|
||||
*/
|
||||
buildId: string;
|
||||
/**
|
||||
* Options for draft mode.
|
||||
*/
|
||||
previewProps: __ApiPreviewProps;
|
||||
}
|
||||
type RustifiedEnv = {
|
||||
name: string;
|
||||
value: string;
|
||||
}[];
|
||||
export interface DefineEnv {
|
||||
client: RustifiedEnv;
|
||||
edge: RustifiedEnv;
|
||||
nodejs: RustifiedEnv;
|
||||
}
|
||||
export declare function createDefineEnv({ isTurbopack, clientRouterFilters, config, dev, distDir, fetchCacheKeyPrefix, hasRewrites, middlewareMatchers, }: Omit<DefineEnvPluginOptions, 'isClient' | 'isNodeOrEdgeCompilation' | 'isEdgeServer' | 'isNodeServer'>): DefineEnv;
|
||||
export interface TurboEngineOptions {
|
||||
/**
|
||||
* An upper bound of memory that turbopack will attempt to stay under.
|
||||
*/
|
||||
memoryLimit?: number;
|
||||
}
|
||||
export type StyledString = {
|
||||
type: 'text';
|
||||
value: string;
|
||||
} | {
|
||||
type: 'code';
|
||||
value: string;
|
||||
} | {
|
||||
type: 'strong';
|
||||
value: string;
|
||||
} | {
|
||||
type: 'stack';
|
||||
value: StyledString[];
|
||||
} | {
|
||||
type: 'line';
|
||||
value: StyledString[];
|
||||
};
|
||||
export interface Issue {
|
||||
severity: string;
|
||||
stage: string;
|
||||
filePath: string;
|
||||
title: StyledString;
|
||||
description?: StyledString;
|
||||
detail?: StyledString;
|
||||
source?: {
|
||||
source: {
|
||||
ident: string;
|
||||
content?: string;
|
||||
};
|
||||
range?: {
|
||||
start: {
|
||||
line: number;
|
||||
column: number;
|
||||
};
|
||||
end: {
|
||||
line: number;
|
||||
column: number;
|
||||
};
|
||||
};
|
||||
};
|
||||
documentationLink: string;
|
||||
subIssues: Issue[];
|
||||
}
|
||||
export interface Diagnostics {
|
||||
category: string;
|
||||
name: string;
|
||||
payload: unknown;
|
||||
}
|
||||
export type TurbopackResult<T = {}> = T & {
|
||||
issues: Issue[];
|
||||
diagnostics: Diagnostics[];
|
||||
};
|
||||
export interface Middleware {
|
||||
endpoint: Endpoint;
|
||||
}
|
||||
export interface Instrumentation {
|
||||
nodeJs: Endpoint;
|
||||
edge: Endpoint;
|
||||
}
|
||||
export interface Entrypoints {
|
||||
routes: Map<string, Route>;
|
||||
middleware?: Middleware;
|
||||
instrumentation?: Instrumentation;
|
||||
pagesDocumentEndpoint: Endpoint;
|
||||
pagesAppEndpoint: Endpoint;
|
||||
pagesErrorEndpoint: Endpoint;
|
||||
}
|
||||
interface BaseUpdate {
|
||||
resource: {
|
||||
headers: unknown;
|
||||
path: string;
|
||||
};
|
||||
diagnostics: unknown[];
|
||||
issues: Issue[];
|
||||
}
|
||||
interface IssuesUpdate extends BaseUpdate {
|
||||
type: 'issues';
|
||||
}
|
||||
interface EcmascriptMergedUpdate {
|
||||
type: 'EcmascriptMergedUpdate';
|
||||
chunks: {
|
||||
[moduleName: string]: {
|
||||
type: 'partial';
|
||||
};
|
||||
};
|
||||
entries: {
|
||||
[moduleName: string]: {
|
||||
code: string;
|
||||
map: string;
|
||||
url: string;
|
||||
};
|
||||
};
|
||||
}
|
||||
interface PartialUpdate extends BaseUpdate {
|
||||
type: 'partial';
|
||||
instruction: {
|
||||
type: 'ChunkListUpdate';
|
||||
merged: EcmascriptMergedUpdate[] | undefined;
|
||||
};
|
||||
}
|
||||
export type Update = IssuesUpdate | PartialUpdate;
|
||||
export interface HmrIdentifiers {
|
||||
identifiers: string[];
|
||||
}
|
||||
/** @see https://github.com/vercel/next.js/blob/415cd74b9a220b6f50da64da68c13043e9b02995/packages/next-swc/crates/napi/src/next_api/project.rs#L824-L833 */
|
||||
export interface TurbopackStackFrame {
|
||||
isServer: boolean;
|
||||
isInternal?: boolean;
|
||||
file: string;
|
||||
/** 1-indexed, unlike source map tokens */
|
||||
line?: number;
|
||||
/** 1-indexed, unlike source map tokens */
|
||||
column?: number | null;
|
||||
methodName?: string;
|
||||
}
|
||||
export type UpdateMessage = {
|
||||
updateType: 'start';
|
||||
} | {
|
||||
updateType: 'end';
|
||||
value: UpdateInfo;
|
||||
};
|
||||
export interface UpdateInfo {
|
||||
duration: number;
|
||||
tasks: number;
|
||||
}
|
||||
export interface Project {
|
||||
update(options: Partial<ProjectOptions>): Promise<void>;
|
||||
entrypointsSubscribe(): AsyncIterableIterator<TurbopackResult<Entrypoints>>;
|
||||
hmrEvents(identifier: string): AsyncIterableIterator<TurbopackResult<Update>>;
|
||||
hmrIdentifiersSubscribe(): AsyncIterableIterator<TurbopackResult<HmrIdentifiers>>;
|
||||
getSourceForAsset(filePath: string): Promise<string | null>;
|
||||
traceSource(stackFrame: TurbopackStackFrame): Promise<TurbopackStackFrame | null>;
|
||||
updateInfoSubscribe(aggregationMs: number): AsyncIterableIterator<TurbopackResult<UpdateMessage>>;
|
||||
}
|
||||
export type Route = {
|
||||
type: 'conflict';
|
||||
} | {
|
||||
type: 'app-page';
|
||||
pages: {
|
||||
originalName: string;
|
||||
htmlEndpoint: Endpoint;
|
||||
rscEndpoint: Endpoint;
|
||||
}[];
|
||||
} | {
|
||||
type: 'app-route';
|
||||
originalName: string;
|
||||
endpoint: Endpoint;
|
||||
} | {
|
||||
type: 'page';
|
||||
htmlEndpoint: Endpoint;
|
||||
dataEndpoint: Endpoint;
|
||||
} | {
|
||||
type: 'page-api';
|
||||
endpoint: Endpoint;
|
||||
};
|
||||
export interface Endpoint {
|
||||
/** Write files for the endpoint to disk. */
|
||||
writeToDisk(): Promise<TurbopackResult<WrittenEndpoint>>;
|
||||
/**
|
||||
* Listen to client-side changes to the endpoint.
|
||||
* After clientChanged() has been awaited it will listen to changes.
|
||||
* The async iterator will yield for each change.
|
||||
*/
|
||||
clientChanged(): Promise<AsyncIterableIterator<TurbopackResult>>;
|
||||
/**
|
||||
* Listen to server-side changes to the endpoint.
|
||||
* After serverChanged() has been awaited it will listen to changes.
|
||||
* The async iterator will yield for each change.
|
||||
*/
|
||||
serverChanged(includeIssues: boolean): Promise<AsyncIterableIterator<TurbopackResult>>;
|
||||
}
|
||||
interface EndpointConfig {
|
||||
dynamic?: 'auto' | 'force-dynamic' | 'error' | 'force-static';
|
||||
dynamicParams?: boolean;
|
||||
revalidate?: 'never' | 'force-cache' | number;
|
||||
fetchCache?: 'auto' | 'default-cache' | 'only-cache' | 'force-cache' | 'default-no-store' | 'only-no-store' | 'force-no-store';
|
||||
runtime?: 'nodejs' | 'edge';
|
||||
preferredRegion?: string;
|
||||
}
|
||||
export type ServerPath = {
|
||||
path: string;
|
||||
contentHash: string;
|
||||
};
|
||||
export type WrittenEndpoint = {
|
||||
type: 'nodejs';
|
||||
/** The entry path for the endpoint. */
|
||||
entryPath: string;
|
||||
/** All client paths that have been written for the endpoint. */
|
||||
clientPaths: string[];
|
||||
/** All server paths that have been written for the endpoint. */
|
||||
serverPaths: ServerPath[];
|
||||
config: EndpointConfig;
|
||||
} | {
|
||||
type: 'edge';
|
||||
/** All client paths that have been written for the endpoint. */
|
||||
clientPaths: string[];
|
||||
/** All server paths that have been written for the endpoint. */
|
||||
serverPaths: ServerPath[];
|
||||
config: EndpointConfig;
|
||||
};
|
||||
export declare function isWasm(): Promise<boolean>;
|
||||
export declare function transform(src: string, options?: any): Promise<any>;
|
||||
export declare function transformSync(src: string, options?: any): any;
|
||||
export declare function minify(src: string, options: any): Promise<string>;
|
||||
export declare function minifySync(src: string, options: any): string;
|
||||
export declare function parse(src: string, options: any): Promise<any>;
|
||||
export declare function getBinaryMetadata(): {
|
||||
target: any;
|
||||
};
|
||||
/**
|
||||
* Initialize trace subscriber to emit traces.
|
||||
*
|
||||
*/
|
||||
export declare const initCustomTraceSubscriber: (traceFileName?: string) => void;
|
||||
/**
|
||||
* Initialize heap profiler, if possible.
|
||||
* Note this is not available in release build of next-swc by default,
|
||||
* only available by manually building next-swc with specific flags.
|
||||
* Calling in release build will not do anything.
|
||||
*/
|
||||
export declare const initHeapProfiler: () => void;
|
||||
/**
|
||||
* Teardown heap profiler, if possible.
|
||||
*
|
||||
* Same as initialization, this is not available in release build of next-swc by default
|
||||
* and calling it will not do anything.
|
||||
*/
|
||||
export declare const teardownHeapProfiler: () => void;
|
||||
/**
|
||||
* 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 declare const teardownTraceSubscriber: () => void;
|
||||
export {};
|
||||
974
node_modules/next/dist/build/swc/index.js
generated
vendored
Normal file
974
node_modules/next/dist/build/swc/index.js
generated
vendored
Normal file
@ -0,0 +1,974 @@
|
||||
/* eslint-disable @typescript-eslint/no-use-before-define */ "use strict";
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
0 && (module.exports = {
|
||||
createDefineEnv: null,
|
||||
getBinaryMetadata: null,
|
||||
getSupportedArchTriples: null,
|
||||
initCustomTraceSubscriber: null,
|
||||
initHeapProfiler: null,
|
||||
isWasm: null,
|
||||
loadBindings: null,
|
||||
lockfilePatchPromise: null,
|
||||
minify: null,
|
||||
minifySync: null,
|
||||
parse: null,
|
||||
teardownHeapProfiler: null,
|
||||
teardownTraceSubscriber: null,
|
||||
transform: null,
|
||||
transformSync: null
|
||||
});
|
||||
function _export(target, all) {
|
||||
for(var name in all)Object.defineProperty(target, name, {
|
||||
enumerable: true,
|
||||
get: all[name]
|
||||
});
|
||||
}
|
||||
_export(exports, {
|
||||
createDefineEnv: function() {
|
||||
return createDefineEnv;
|
||||
},
|
||||
getBinaryMetadata: function() {
|
||||
return getBinaryMetadata;
|
||||
},
|
||||
getSupportedArchTriples: function() {
|
||||
return getSupportedArchTriples;
|
||||
},
|
||||
initCustomTraceSubscriber: function() {
|
||||
return initCustomTraceSubscriber;
|
||||
},
|
||||
initHeapProfiler: function() {
|
||||
return initHeapProfiler;
|
||||
},
|
||||
isWasm: function() {
|
||||
return isWasm;
|
||||
},
|
||||
loadBindings: function() {
|
||||
return loadBindings;
|
||||
},
|
||||
lockfilePatchPromise: function() {
|
||||
return lockfilePatchPromise;
|
||||
},
|
||||
minify: function() {
|
||||
return minify;
|
||||
},
|
||||
minifySync: function() {
|
||||
return minifySync;
|
||||
},
|
||||
parse: function() {
|
||||
return parse;
|
||||
},
|
||||
teardownHeapProfiler: function() {
|
||||
return teardownHeapProfiler;
|
||||
},
|
||||
teardownTraceSubscriber: function() {
|
||||
return teardownTraceSubscriber;
|
||||
},
|
||||
transform: function() {
|
||||
return transform;
|
||||
},
|
||||
transformSync: function() {
|
||||
return transformSync;
|
||||
}
|
||||
});
|
||||
const _path = /*#__PURE__*/ _interop_require_default(require("path"));
|
||||
const _url = require("url");
|
||||
const _os = require("os");
|
||||
const _triples = require("next/dist/compiled/@napi-rs/triples");
|
||||
const _log = /*#__PURE__*/ _interop_require_wildcard(require("../output/log"));
|
||||
const _options = require("./options");
|
||||
const _swcloadfailure = require("../../telemetry/events/swc-load-failure");
|
||||
const _patchincorrectlockfile = require("../../lib/patch-incorrect-lockfile");
|
||||
const _downloadswc = require("../../lib/download-swc");
|
||||
const _util = require("util");
|
||||
const _defineenvplugin = require("../webpack/plugins/define-env-plugin");
|
||||
function _interop_require_default(obj) {
|
||||
return obj && obj.__esModule ? obj : {
|
||||
default: obj
|
||||
};
|
||||
}
|
||||
function _getRequireWildcardCache(nodeInterop) {
|
||||
if (typeof WeakMap !== "function") return null;
|
||||
var cacheBabelInterop = new WeakMap();
|
||||
var cacheNodeInterop = new WeakMap();
|
||||
return (_getRequireWildcardCache = function(nodeInterop) {
|
||||
return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
|
||||
})(nodeInterop);
|
||||
}
|
||||
function _interop_require_wildcard(obj, nodeInterop) {
|
||||
if (!nodeInterop && obj && obj.__esModule) {
|
||||
return obj;
|
||||
}
|
||||
if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
|
||||
return {
|
||||
default: obj
|
||||
};
|
||||
}
|
||||
var cache = _getRequireWildcardCache(nodeInterop);
|
||||
if (cache && cache.has(obj)) {
|
||||
return cache.get(obj);
|
||||
}
|
||||
var newObj = {
|
||||
__proto__: null
|
||||
};
|
||||
var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
|
||||
for(var key in obj){
|
||||
if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
|
||||
var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
|
||||
if (desc && (desc.get || desc.set)) {
|
||||
Object.defineProperty(newObj, key, desc);
|
||||
} else {
|
||||
newObj[key] = obj[key];
|
||||
}
|
||||
}
|
||||
}
|
||||
newObj.default = obj;
|
||||
if (cache) {
|
||||
cache.set(obj, newObj);
|
||||
}
|
||||
return newObj;
|
||||
}
|
||||
const nextVersion = "14.2.13";
|
||||
const ArchName = (0, _os.arch)();
|
||||
const PlatformName = (0, _os.platform)();
|
||||
const infoLog = (...args)=>{
|
||||
if (process.env.NEXT_PRIVATE_BUILD_WORKER) {
|
||||
return;
|
||||
}
|
||||
if (process.env.DEBUG) {
|
||||
_log.info(...args);
|
||||
}
|
||||
};
|
||||
const getSupportedArchTriples = ()=>{
|
||||
const { darwin, win32, linux, freebsd, android } = _triples.platformArchTriples;
|
||||
return {
|
||||
darwin,
|
||||
win32: {
|
||||
arm64: win32.arm64,
|
||||
ia32: win32.ia32.filter((triple)=>triple.abi === "msvc"),
|
||||
x64: win32.x64.filter((triple)=>triple.abi === "msvc")
|
||||
},
|
||||
linux: {
|
||||
// linux[x64] includes `gnux32` abi, with x64 arch.
|
||||
x64: linux.x64.filter((triple)=>triple.abi !== "gnux32"),
|
||||
arm64: linux.arm64,
|
||||
// This target is being deprecated, however we keep it in `knownDefaultWasmFallbackTriples` for now
|
||||
arm: linux.arm
|
||||
},
|
||||
// Below targets are being deprecated, however we keep it in `knownDefaultWasmFallbackTriples` for now
|
||||
freebsd: {
|
||||
x64: freebsd.x64
|
||||
},
|
||||
android: {
|
||||
arm64: android.arm64,
|
||||
arm: android.arm
|
||||
}
|
||||
};
|
||||
};
|
||||
const triples = (()=>{
|
||||
var _supportedArchTriples_PlatformName, _platformArchTriples_PlatformName;
|
||||
const supportedArchTriples = getSupportedArchTriples();
|
||||
const targetTriple = (_supportedArchTriples_PlatformName = supportedArchTriples[PlatformName]) == null ? void 0 : _supportedArchTriples_PlatformName[ArchName];
|
||||
// If we have supported triple, return it right away
|
||||
if (targetTriple) {
|
||||
return targetTriple;
|
||||
}
|
||||
// If there isn't corresponding target triple in `supportedArchTriples`, check if it's excluded from original raw triples
|
||||
// Otherwise, it is completely unsupported platforms.
|
||||
let rawTargetTriple = (_platformArchTriples_PlatformName = _triples.platformArchTriples[PlatformName]) == null ? void 0 : _platformArchTriples_PlatformName[ArchName];
|
||||
if (rawTargetTriple) {
|
||||
_log.warn(`Trying to load next-swc for target triple ${rawTargetTriple}, but there next-swc does not have native bindings support`);
|
||||
} else {
|
||||
_log.warn(`Trying to load next-swc for unsupported platforms ${PlatformName}/${ArchName}`);
|
||||
}
|
||||
return [];
|
||||
})();
|
||||
// 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 guarantee.
|
||||
const __INTERNAL_CUSTOM_TURBOPACK_BINDINGS = process.env.__INTERNAL_CUSTOM_TURBOPACK_BINDINGS;
|
||||
function checkVersionMismatch(pkgData) {
|
||||
const version = pkgData.version;
|
||||
if (version && version !== nextVersion) {
|
||||
_log.warn(`Mismatching @next/swc version, detected: ${version} while Next.js is on ${nextVersion}. Please ensure these match`);
|
||||
}
|
||||
}
|
||||
// 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 = [
|
||||
"x86_64-unknown-freebsd",
|
||||
"aarch64-linux-android",
|
||||
"arm-linux-androideabi",
|
||||
"armv7-unknown-linux-gnueabihf",
|
||||
"i686-pc-windows-msvc"
|
||||
];
|
||||
// The last attempt's error code returned when cjs require to native bindings fails.
|
||||
// If node.js throws an error without error code, this should be `unknown` instead of undefined.
|
||||
// For the wasm-first targets (`knownDefaultWasmFallbackTriples`) this will be `unsupported_target`.
|
||||
let lastNativeBindingsLoadErrorCode = undefined;
|
||||
let nativeBindings;
|
||||
let wasmBindings;
|
||||
let downloadWasmPromise;
|
||||
let pendingBindings;
|
||||
let swcTraceFlushGuard;
|
||||
let swcHeapProfilerFlushGuard;
|
||||
let downloadNativeBindingsPromise = undefined;
|
||||
const lockfilePatchPromise = {};
|
||||
async function loadBindings(useWasmBinary = false) {
|
||||
// Increase Rust stack size as some npm packages being compiled need more than the default.
|
||||
if (!process.env.RUST_MIN_STACK) {
|
||||
process.env.RUST_MIN_STACK = "8388608";
|
||||
}
|
||||
if (pendingBindings) {
|
||||
return pendingBindings;
|
||||
}
|
||||
// rust needs stdout to be blocking, otherwise it will throw an error (on macOS at least) when writing a lot of data (logs) to it
|
||||
// see https://github.com/napi-rs/napi-rs/issues/1630
|
||||
// and https://github.com/nodejs/node/blob/main/doc/api/process.md#a-note-on-process-io
|
||||
if (process.stdout._handle != null) {
|
||||
// @ts-ignore
|
||||
process.stdout._handle.setBlocking == null ? void 0 : process.stdout._handle.setBlocking.call(process.stdout._handle, true);
|
||||
}
|
||||
if (process.stderr._handle != null) {
|
||||
// @ts-ignore
|
||||
process.stderr._handle.setBlocking == null ? void 0 : process.stderr._handle.setBlocking.call(process.stderr._handle, true);
|
||||
}
|
||||
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 = (0, _patchincorrectlockfile.patchIncorrectLockfile)(process.cwd()).catch(console.error);
|
||||
}
|
||||
let attempts = [];
|
||||
const disableWasmFallback = process.env.NEXT_DISABLE_SWC_WASM;
|
||||
const unsupportedPlatform = triples.some((triple)=>!!(triple == null ? void 0 : triple.raw) && knownDefaultWasmFallbackTriples.includes(triple.raw));
|
||||
const isWebContainer = process.versions.webcontainer;
|
||||
const shouldLoadWasmFallbackFirst = !disableWasmFallback && unsupportedPlatform && useWasmBinary || isWebContainer;
|
||||
if (!unsupportedPlatform && useWasmBinary) {
|
||||
_log.warn(`experimental.useWasmBinary is not an option for supported platform ${PlatformName}/${ArchName} and will be ignored.`);
|
||||
}
|
||||
if (shouldLoadWasmFallbackFirst) {
|
||||
lastNativeBindingsLoadErrorCode = "unsupported_target";
|
||||
const fallbackBindings = await tryLoadWasmWithFallback(attempts);
|
||||
if (fallbackBindings) {
|
||||
return resolve(fallbackBindings);
|
||||
}
|
||||
}
|
||||
// Trickle down loading `fallback` bindings:
|
||||
//
|
||||
// - First, try to load native bindings installed in node_modules.
|
||||
// - If that fails with `ERR_MODULE_NOT_FOUND`, treat it as case of https://github.com/npm/cli/issues/4828
|
||||
// that host system where generated package lock is not matching to the guest system running on, try to manually
|
||||
// download corresponding target triple and load it. This won't be triggered if native bindings are failed to load
|
||||
// with other reasons than `ERR_MODULE_NOT_FOUND`.
|
||||
// - Lastly, falls back to wasm binding where possible.
|
||||
try {
|
||||
return resolve(loadNative());
|
||||
} catch (a) {
|
||||
if (Array.isArray(a) && a.every((m)=>m.includes("it was not installed"))) {
|
||||
let fallbackBindings = await tryLoadNativeWithFallback(attempts);
|
||||
if (fallbackBindings) {
|
||||
return resolve(fallbackBindings);
|
||||
}
|
||||
}
|
||||
attempts = attempts.concat(a);
|
||||
}
|
||||
logLoadFailure(attempts, true);
|
||||
});
|
||||
return pendingBindings;
|
||||
}
|
||||
async function tryLoadNativeWithFallback(attempts) {
|
||||
const nativeBindingsDirectory = _path.default.join(_path.default.dirname(require.resolve("next/package.json")), "next-swc-fallback");
|
||||
if (!downloadNativeBindingsPromise) {
|
||||
downloadNativeBindingsPromise = (0, _downloadswc.downloadNativeNextSwc)(nextVersion, nativeBindingsDirectory, triples.map((triple)=>triple.platformArchABI));
|
||||
}
|
||||
await downloadNativeBindingsPromise;
|
||||
try {
|
||||
let bindings = loadNative(nativeBindingsDirectory);
|
||||
return bindings;
|
||||
} catch (a) {
|
||||
attempts.concat(a);
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
async function tryLoadWasmWithFallback(attempts) {
|
||||
try {
|
||||
let bindings = await loadWasm("");
|
||||
// @ts-expect-error TODO: this event has a wrong type.
|
||||
(0, _swcloadfailure.eventSwcLoadFailure)({
|
||||
wasm: "enabled",
|
||||
nativeBindingsErrorCode: lastNativeBindingsLoadErrorCode
|
||||
});
|
||||
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.default.join(_path.default.dirname(require.resolve("next/package.json")), "wasm");
|
||||
if (!downloadWasmPromise) {
|
||||
downloadWasmPromise = (0, _downloadswc.downloadWasmSwc)(nextVersion, wasmDirectory);
|
||||
}
|
||||
await downloadWasmPromise;
|
||||
let bindings = await loadWasm(wasmDirectory);
|
||||
// @ts-expect-error TODO: this event has a wrong type.
|
||||
(0, _swcloadfailure.eventSwcLoadFailure)({
|
||||
wasm: "fallback",
|
||||
nativeBindingsErrorCode: lastNativeBindingsLoadErrorCode
|
||||
});
|
||||
// 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 (a) {
|
||||
attempts = attempts.concat(a);
|
||||
}
|
||||
}
|
||||
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);
|
||||
}
|
||||
// @ts-expect-error TODO: this event has a wrong type.
|
||||
(0, _swcloadfailure.eventSwcLoadFailure)({
|
||||
wasm: triedWasm ? "failed" : undefined,
|
||||
nativeBindingsErrorCode: lastNativeBindingsLoadErrorCode
|
||||
}).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);
|
||||
});
|
||||
}
|
||||
function createDefineEnv({ isTurbopack, clientRouterFilters, config, dev, distDir, fetchCacheKeyPrefix, hasRewrites, middlewareMatchers }) {
|
||||
let defineEnv = {
|
||||
client: [],
|
||||
edge: [],
|
||||
nodejs: []
|
||||
};
|
||||
for (const variant of Object.keys(defineEnv)){
|
||||
defineEnv[variant] = rustifyEnv((0, _defineenvplugin.getDefineEnv)({
|
||||
isTurbopack,
|
||||
clientRouterFilters,
|
||||
config,
|
||||
dev,
|
||||
distDir,
|
||||
fetchCacheKeyPrefix,
|
||||
hasRewrites,
|
||||
isClient: variant === "client",
|
||||
isEdgeServer: variant === "edge",
|
||||
isNodeOrEdgeCompilation: variant === "nodejs" || variant === "edge",
|
||||
isNodeServer: variant === "nodejs",
|
||||
middlewareMatchers
|
||||
}));
|
||||
}
|
||||
return defineEnv;
|
||||
}
|
||||
function rustifyEnv(env) {
|
||||
return Object.entries(env).filter(([_, value])=>value != null).map(([name, value])=>({
|
||||
name,
|
||||
value
|
||||
}));
|
||||
}
|
||||
// TODO(sokra) Support wasm option.
|
||||
function bindingToApi(binding, _wasm) {
|
||||
const cancel = new class Cancel extends Error {
|
||||
}();
|
||||
/**
|
||||
* Utility function to ensure all variants of an enum are handled.
|
||||
*/ function invariant(never, computeMessage) {
|
||||
throw new Error(`Invariant: ${computeMessage(never)}`);
|
||||
}
|
||||
async function withErrorCause(fn) {
|
||||
try {
|
||||
return await fn();
|
||||
} catch (nativeError) {
|
||||
throw new Error(nativeError.message, {
|
||||
cause: nativeError
|
||||
});
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Calls a native function and streams the result.
|
||||
* If useBuffer is true, all values will be preserved, potentially buffered
|
||||
* if consumed slower than produced. Else, only the latest value will be
|
||||
* preserved.
|
||||
*/ function subscribe(useBuffer, nativeFunction) {
|
||||
// A buffer of produced items. This will only contain values if the
|
||||
// consumer is slower than the producer.
|
||||
let buffer = [];
|
||||
// A deferred value waiting for the next produced item. This will only
|
||||
// exist if the consumer is faster than the producer.
|
||||
let waiting;
|
||||
let canceled = false;
|
||||
// The native function will call this every time it emits a new result. We
|
||||
// either need to notify a waiting consumer, or buffer the new result until
|
||||
// the consumer catches up.
|
||||
const emitResult = (err, value)=>{
|
||||
if (waiting) {
|
||||
let { resolve, reject } = waiting;
|
||||
waiting = undefined;
|
||||
if (err) reject(err);
|
||||
else resolve(value);
|
||||
} else {
|
||||
const item = {
|
||||
err,
|
||||
value
|
||||
};
|
||||
if (useBuffer) buffer.push(item);
|
||||
else buffer[0] = item;
|
||||
}
|
||||
};
|
||||
const iterator = async function*() {
|
||||
const task = await withErrorCause(()=>nativeFunction(emitResult));
|
||||
try {
|
||||
while(!canceled){
|
||||
if (buffer.length > 0) {
|
||||
const item = buffer.shift();
|
||||
if (item.err) throw item.err;
|
||||
yield item.value;
|
||||
} else {
|
||||
// eslint-disable-next-line no-loop-func
|
||||
yield new Promise((resolve, reject)=>{
|
||||
waiting = {
|
||||
resolve,
|
||||
reject
|
||||
};
|
||||
});
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
if (e === cancel) return;
|
||||
throw e;
|
||||
} finally{
|
||||
binding.rootTaskDispose(task);
|
||||
}
|
||||
}();
|
||||
iterator.return = async ()=>{
|
||||
canceled = true;
|
||||
if (waiting) waiting.reject(cancel);
|
||||
return {
|
||||
value: undefined,
|
||||
done: true
|
||||
};
|
||||
};
|
||||
return iterator;
|
||||
}
|
||||
async function rustifyProjectOptions(options) {
|
||||
return {
|
||||
...options,
|
||||
nextConfig: options.nextConfig && await serializeNextConfig(options.nextConfig, options.projectPath),
|
||||
jsConfig: options.jsConfig && JSON.stringify(options.jsConfig),
|
||||
env: options.env && rustifyEnv(options.env),
|
||||
defineEnv: options.defineEnv
|
||||
};
|
||||
}
|
||||
class ProjectImpl {
|
||||
constructor(nativeProject){
|
||||
this._nativeProject = nativeProject;
|
||||
}
|
||||
async update(options) {
|
||||
await withErrorCause(async ()=>binding.projectUpdate(this._nativeProject, await rustifyProjectOptions(options)));
|
||||
}
|
||||
entrypointsSubscribe() {
|
||||
const subscription = subscribe(false, async (callback)=>binding.projectEntrypointsSubscribe(this._nativeProject, callback));
|
||||
return async function*() {
|
||||
for await (const entrypoints of subscription){
|
||||
const routes = new Map();
|
||||
for (const { pathname, ...nativeRoute } of entrypoints.routes){
|
||||
let route;
|
||||
const routeType = nativeRoute.type;
|
||||
switch(routeType){
|
||||
case "page":
|
||||
route = {
|
||||
type: "page",
|
||||
htmlEndpoint: new EndpointImpl(nativeRoute.htmlEndpoint),
|
||||
dataEndpoint: new EndpointImpl(nativeRoute.dataEndpoint)
|
||||
};
|
||||
break;
|
||||
case "page-api":
|
||||
route = {
|
||||
type: "page-api",
|
||||
endpoint: new EndpointImpl(nativeRoute.endpoint)
|
||||
};
|
||||
break;
|
||||
case "app-page":
|
||||
route = {
|
||||
type: "app-page",
|
||||
pages: nativeRoute.pages.map((page)=>({
|
||||
originalName: page.originalName,
|
||||
htmlEndpoint: new EndpointImpl(page.htmlEndpoint),
|
||||
rscEndpoint: new EndpointImpl(page.rscEndpoint)
|
||||
}))
|
||||
};
|
||||
break;
|
||||
case "app-route":
|
||||
route = {
|
||||
type: "app-route",
|
||||
originalName: nativeRoute.originalName,
|
||||
endpoint: new EndpointImpl(nativeRoute.endpoint)
|
||||
};
|
||||
break;
|
||||
case "conflict":
|
||||
route = {
|
||||
type: "conflict"
|
||||
};
|
||||
break;
|
||||
default:
|
||||
const _exhaustiveCheck = routeType;
|
||||
invariant(nativeRoute, ()=>`Unknown route type: ${_exhaustiveCheck}`);
|
||||
}
|
||||
routes.set(pathname, route);
|
||||
}
|
||||
const napiMiddlewareToMiddleware = (middleware)=>({
|
||||
endpoint: new EndpointImpl(middleware.endpoint),
|
||||
runtime: middleware.runtime,
|
||||
matcher: middleware.matcher
|
||||
});
|
||||
const middleware = entrypoints.middleware ? napiMiddlewareToMiddleware(entrypoints.middleware) : undefined;
|
||||
const napiInstrumentationToInstrumentation = (instrumentation)=>({
|
||||
nodeJs: new EndpointImpl(instrumentation.nodeJs),
|
||||
edge: new EndpointImpl(instrumentation.edge)
|
||||
});
|
||||
const instrumentation = entrypoints.instrumentation ? napiInstrumentationToInstrumentation(entrypoints.instrumentation) : undefined;
|
||||
yield {
|
||||
routes,
|
||||
middleware,
|
||||
instrumentation,
|
||||
pagesDocumentEndpoint: new EndpointImpl(entrypoints.pagesDocumentEndpoint),
|
||||
pagesAppEndpoint: new EndpointImpl(entrypoints.pagesAppEndpoint),
|
||||
pagesErrorEndpoint: new EndpointImpl(entrypoints.pagesErrorEndpoint),
|
||||
issues: entrypoints.issues,
|
||||
diagnostics: entrypoints.diagnostics
|
||||
};
|
||||
}
|
||||
}();
|
||||
}
|
||||
hmrEvents(identifier) {
|
||||
return subscribe(true, async (callback)=>binding.projectHmrEvents(this._nativeProject, identifier, callback));
|
||||
}
|
||||
hmrIdentifiersSubscribe() {
|
||||
return subscribe(false, async (callback)=>binding.projectHmrIdentifiersSubscribe(this._nativeProject, callback));
|
||||
}
|
||||
traceSource(stackFrame) {
|
||||
return binding.projectTraceSource(this._nativeProject, stackFrame);
|
||||
}
|
||||
getSourceForAsset(filePath) {
|
||||
return binding.projectGetSourceForAsset(this._nativeProject, filePath);
|
||||
}
|
||||
updateInfoSubscribe(aggregationMs) {
|
||||
const subscription = subscribe(true, async (callback)=>binding.projectUpdateInfoSubscribe(this._nativeProject, aggregationMs, callback));
|
||||
return subscription;
|
||||
}
|
||||
}
|
||||
class EndpointImpl {
|
||||
constructor(nativeEndpoint){
|
||||
this._nativeEndpoint = nativeEndpoint;
|
||||
}
|
||||
async writeToDisk() {
|
||||
return await withErrorCause(()=>binding.endpointWriteToDisk(this._nativeEndpoint));
|
||||
}
|
||||
async clientChanged() {
|
||||
const clientSubscription = subscribe(false, async (callback)=>binding.endpointClientChangedSubscribe(await this._nativeEndpoint, callback));
|
||||
await clientSubscription.next();
|
||||
return clientSubscription;
|
||||
}
|
||||
async serverChanged(includeIssues) {
|
||||
const serverSubscription = subscribe(false, async (callback)=>binding.endpointServerChangedSubscribe(await this._nativeEndpoint, includeIssues, callback));
|
||||
await serverSubscription.next();
|
||||
return serverSubscription;
|
||||
}
|
||||
}
|
||||
async function serializeNextConfig(nextConfig, projectPath) {
|
||||
var _nextConfig_experimental_turbo, _nextConfig_experimental;
|
||||
// Avoid mutating the existing `nextConfig` object.
|
||||
let nextConfigSerializable = {
|
||||
...nextConfig
|
||||
};
|
||||
nextConfigSerializable.generateBuildId = await (nextConfig.generateBuildId == null ? void 0 : nextConfig.generateBuildId.call(nextConfig));
|
||||
// TODO: these functions takes arguments, have to be supported in a different way
|
||||
nextConfigSerializable.exportPathMap = {};
|
||||
nextConfigSerializable.webpack = nextConfig.webpack && {};
|
||||
if ((_nextConfig_experimental = nextConfig.experimental) == null ? void 0 : (_nextConfig_experimental_turbo = _nextConfig_experimental.turbo) == null ? void 0 : _nextConfig_experimental_turbo.rules) {
|
||||
var _nextConfig_experimental_turbo1;
|
||||
ensureLoadersHaveSerializableOptions((_nextConfig_experimental_turbo1 = nextConfig.experimental.turbo) == null ? void 0 : _nextConfig_experimental_turbo1.rules);
|
||||
}
|
||||
nextConfigSerializable.modularizeImports = nextConfigSerializable.modularizeImports ? Object.fromEntries(Object.entries(nextConfigSerializable.modularizeImports).map(([mod, config])=>[
|
||||
mod,
|
||||
{
|
||||
...config,
|
||||
transform: typeof config.transform === "string" ? config.transform : Object.entries(config.transform).map(([key, value])=>[
|
||||
key,
|
||||
value
|
||||
])
|
||||
}
|
||||
])) : undefined;
|
||||
// loaderFile is an absolute path, we need it to be relative for turbopack.
|
||||
if (nextConfigSerializable.images.loaderFile) {
|
||||
nextConfigSerializable.images = {
|
||||
...nextConfig.images,
|
||||
loaderFile: "./" + _path.default.relative(projectPath, nextConfig.images.loaderFile)
|
||||
};
|
||||
}
|
||||
return JSON.stringify(nextConfigSerializable, null, 2);
|
||||
}
|
||||
function ensureLoadersHaveSerializableOptions(turbopackRules) {
|
||||
for (const [glob, rule] of Object.entries(turbopackRules)){
|
||||
if (Array.isArray(rule)) {
|
||||
checkLoaderItems(rule, glob);
|
||||
} else {
|
||||
checkConfigItem(rule, glob);
|
||||
}
|
||||
}
|
||||
function checkConfigItem(rule, glob) {
|
||||
if (!rule) return;
|
||||
if ("loaders" in rule) {
|
||||
checkLoaderItems(rule.loaders, glob);
|
||||
} else {
|
||||
for(const key in rule){
|
||||
const inner = rule[key];
|
||||
if (typeof inner === "object" && inner) {
|
||||
checkConfigItem(inner, glob);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
function checkLoaderItems(loaderItems, glob) {
|
||||
for (const loaderItem of loaderItems){
|
||||
if (typeof loaderItem !== "string" && !(0, _util.isDeepStrictEqual)(loaderItem, JSON.parse(JSON.stringify(loaderItem)))) {
|
||||
throw new Error(`loader ${loaderItem.loader} for match "${glob}" does not have serializable options. Ensure that options passed are plain JavaScript objects and values.`);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
async function createProject(options, turboEngineOptions) {
|
||||
return new ProjectImpl(await binding.projectNew(await rustifyProjectOptions(options), turboEngineOptions || {}));
|
||||
}
|
||||
return createProject;
|
||||
}
|
||||
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.default.join(importPath, pkg, "wasm.js");
|
||||
}
|
||||
let bindings = await import((0, _url.pathToFileURL)(pkgPath).toString());
|
||||
if (pkg === "@next/swc-wasm-web") {
|
||||
bindings = await bindings.default();
|
||||
}
|
||||
infoLog("next-swc build: wasm build @next/swc-wasm-web");
|
||||
// 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) {
|
||||
return bindings.parseSync(src.toString(), options);
|
||||
},
|
||||
getTargetTriple () {
|
||||
return undefined;
|
||||
},
|
||||
turbo: {
|
||||
startTrace: ()=>{
|
||||
_log.error("Wasm binding does not support trace yet");
|
||||
},
|
||||
entrypoints: {
|
||||
stream: (turboTasks, rootDir, applicationDir, pageExtensions, callbackFn)=>{
|
||||
return bindings.streamEntrypoints(turboTasks, rootDir, applicationDir, pageExtensions, callbackFn);
|
||||
},
|
||||
get: (turboTasks, rootDir, applicationDir, pageExtensions)=>{
|
||||
return bindings.getEntrypoints(turboTasks, rootDir, applicationDir, pageExtensions);
|
||||
}
|
||||
}
|
||||
},
|
||||
mdx: {
|
||||
compile: (src, options)=>bindings.mdxCompile(src, getMdxOptions(options)),
|
||||
compileSync: (src, options)=>bindings.mdxCompileSync(src, getMdxOptions(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(importPath) {
|
||||
if (nativeBindings) {
|
||||
return nativeBindings;
|
||||
}
|
||||
const customBindings = !!__INTERNAL_CUSTOM_TURBOPACK_BINDINGS ? require(__INTERNAL_CUSTOM_TURBOPACK_BINDINGS) : null;
|
||||
let bindings;
|
||||
let attempts = [];
|
||||
const NEXT_TEST_NATIVE_DIR = process.env.NEXT_TEST_NATIVE_DIR;
|
||||
for (const triple of triples){
|
||||
if (NEXT_TEST_NATIVE_DIR) {
|
||||
try {
|
||||
// Use the binary directly to skip `pnpm pack` for testing as it's slow because of the large native binary.
|
||||
bindings = require(`${NEXT_TEST_NATIVE_DIR}/next-swc.${triple.platformArchABI}.node`);
|
||||
console.log("next-swc build: local built @next/swc from NEXT_TEST_NATIVE_DIR");
|
||||
break;
|
||||
} catch (e) {}
|
||||
} else {
|
||||
try {
|
||||
bindings = require(`@next/swc/native/next-swc.${triple.platformArchABI}.node`);
|
||||
console.log("next-swc build: local built @next/swc");
|
||||
break;
|
||||
} catch (e) {}
|
||||
}
|
||||
}
|
||||
if (!bindings) {
|
||||
for (const triple of triples){
|
||||
let pkg = importPath ? _path.default.join(importPath, `@next/swc-${triple.platformArchABI}`, `next-swc.${triple.platformArchABI}.node`) : `@next/swc-${triple.platformArchABI}`;
|
||||
try {
|
||||
bindings = require(pkg);
|
||||
if (!importPath) {
|
||||
checkVersionMismatch(require(`${pkg}/package.json`));
|
||||
}
|
||||
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}`);
|
||||
}
|
||||
lastNativeBindingsLoadErrorCode = (e == null ? void 0 : e.code) ?? "unknown";
|
||||
}
|
||||
}
|
||||
}
|
||||
if (bindings) {
|
||||
nativeBindings = {
|
||||
isWasm: false,
|
||||
transform (src, options) {
|
||||
var _options_jsc;
|
||||
const isModule = typeof src !== "undefined" && typeof src !== "string" && !Buffer.isBuffer(src);
|
||||
options = options || {};
|
||||
if (options == null ? void 0 : (_options_jsc = options.jsc) == null ? void 0 : _options_jsc.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 _options_jsc;
|
||||
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 : (_options_jsc = options.jsc) == null ? void 0 : _options_jsc.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,
|
||||
initHeapProfiler: bindings.initHeapProfiler,
|
||||
teardownHeapProfiler: bindings.teardownHeapProfiler,
|
||||
turbo: {
|
||||
startTrace: (options = {}, turboTasks)=>{
|
||||
initHeapProfiler();
|
||||
return (customBindings ?? bindings).runTurboTracing(toBuffer({
|
||||
exact: true,
|
||||
...options
|
||||
}), turboTasks);
|
||||
},
|
||||
createTurboTasks: (memoryLimit)=>bindings.createTurboTasks(memoryLimit),
|
||||
entrypoints: {
|
||||
stream: (turboTasks, rootDir, applicationDir, pageExtensions, fn)=>{
|
||||
return (customBindings ?? bindings).streamEntrypoints(turboTasks, rootDir, applicationDir, pageExtensions, fn);
|
||||
},
|
||||
get: (turboTasks, rootDir, applicationDir, pageExtensions)=>{
|
||||
return (customBindings ?? bindings).getEntrypoints(turboTasks, rootDir, applicationDir, pageExtensions);
|
||||
}
|
||||
},
|
||||
createProject: bindingToApi(customBindings ?? bindings, false)
|
||||
},
|
||||
mdx: {
|
||||
compile: (src, options)=>bindings.mdxCompile(src, toBuffer(getMdxOptions(options))),
|
||||
compileSync: (src, options)=>bindings.mdxCompileSync(src, toBuffer(getMdxOptions(options)))
|
||||
},
|
||||
css: {
|
||||
lightning: {
|
||||
transform: (transformOptions)=>bindings.lightningCssTransform(transformOptions),
|
||||
transformStyleAttr: (transformAttrOptions)=>bindings.lightningCssTransformStyleAttribute(transformAttrOptions)
|
||||
}
|
||||
}
|
||||
};
|
||||
return nativeBindings;
|
||||
}
|
||||
throw attempts;
|
||||
}
|
||||
/// Build a mdx options object contains default values that
|
||||
/// can be parsed with serde_wasm_bindgen.
|
||||
function getMdxOptions(options = {}) {
|
||||
return {
|
||||
...options,
|
||||
development: options.development ?? false,
|
||||
jsx: options.jsx ?? false,
|
||||
parse: options.parse ?? {
|
||||
gfmStrikethroughSingleTilde: true,
|
||||
mathTextSingleDollar: true
|
||||
}
|
||||
};
|
||||
}
|
||||
function toBuffer(t) {
|
||||
return Buffer.from(JSON.stringify(t));
|
||||
}
|
||||
async function isWasm() {
|
||||
let bindings = await loadBindings();
|
||||
return bindings.isWasm;
|
||||
}
|
||||
async function transform(src, options) {
|
||||
let bindings = await loadBindings();
|
||||
return bindings.transform(src, options);
|
||||
}
|
||||
function transformSync(src, options) {
|
||||
let bindings = loadBindingsSync();
|
||||
return bindings.transformSync(src, options);
|
||||
}
|
||||
async function minify(src, options) {
|
||||
let bindings = await loadBindings();
|
||||
return bindings.minify(src, options);
|
||||
}
|
||||
function minifySync(src, options) {
|
||||
let bindings = loadBindingsSync();
|
||||
return bindings.minifySync(src, options);
|
||||
}
|
||||
async function parse(src, options) {
|
||||
let bindings = await loadBindings();
|
||||
let parserOptions = (0, _options.getParserOptions)(options);
|
||||
return bindings.parse(src, parserOptions).then((astStr)=>JSON.parse(astStr));
|
||||
}
|
||||
function getBinaryMetadata() {
|
||||
var _bindings_getTargetTriple;
|
||||
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 = bindings.getTargetTriple) == null ? void 0 : _bindings_getTargetTriple.call(bindings)
|
||||
};
|
||||
}
|
||||
const initCustomTraceSubscriber = (traceFileName)=>{
|
||||
if (!swcTraceFlushGuard) {
|
||||
// Wasm binary doesn't support trace emission
|
||||
let bindings = loadNative();
|
||||
swcTraceFlushGuard = bindings.initCustomTraceSubscriber(traceFileName);
|
||||
}
|
||||
};
|
||||
const initHeapProfiler = ()=>{
|
||||
try {
|
||||
if (!swcHeapProfilerFlushGuard) {
|
||||
let bindings = loadNative();
|
||||
swcHeapProfilerFlushGuard = bindings.initHeapProfiler();
|
||||
}
|
||||
} catch (_) {
|
||||
// Suppress exceptions, this fn allows to fail to load native bindings
|
||||
}
|
||||
};
|
||||
const teardownHeapProfiler = (()=>{
|
||||
let flushed = false;
|
||||
return ()=>{
|
||||
if (!flushed) {
|
||||
flushed = true;
|
||||
try {
|
||||
let bindings = loadNative();
|
||||
if (swcHeapProfilerFlushGuard) {
|
||||
bindings.teardownHeapProfiler(swcHeapProfilerFlushGuard);
|
||||
}
|
||||
} catch (e) {
|
||||
// Suppress exceptions, this fn allows to fail to load native bindings
|
||||
}
|
||||
}
|
||||
};
|
||||
})();
|
||||
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
|
||||
}
|
||||
}
|
||||
};
|
||||
})();
|
||||
|
||||
//# sourceMappingURL=index.js.map
|
||||
1
node_modules/next/dist/build/swc/index.js.map
generated
vendored
Normal file
1
node_modules/next/dist/build/swc/index.js.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
15
node_modules/next/dist/build/swc/jest-transformer.d.ts
generated
vendored
Normal file
15
node_modules/next/dist/build/swc/jest-transformer.d.ts
generated
vendored
Normal file
@ -0,0 +1,15 @@
|
||||
import type { Config } from '@jest/types';
|
||||
import type { NextConfig, ExperimentalConfig } from '../../server/config-shared';
|
||||
import type { ResolvedBaseUrl } from '../load-jsconfig';
|
||||
type TransformerConfig = Config.TransformerConfig[1];
|
||||
export interface JestTransformerConfig extends TransformerConfig {
|
||||
jsConfig: any;
|
||||
resolvedBaseUrl?: ResolvedBaseUrl;
|
||||
pagesDir?: string;
|
||||
serverComponents?: boolean;
|
||||
isEsmProject: boolean;
|
||||
modularizeImports?: NextConfig['modularizeImports'];
|
||||
swcPlugins: ExperimentalConfig['swcPlugins'];
|
||||
compilerOptions: NextConfig['compiler'];
|
||||
}
|
||||
export {};
|
||||
74
node_modules/next/dist/build/swc/jest-transformer.js
generated
vendored
Normal file
74
node_modules/next/dist/build/swc/jest-transformer.js
generated
vendored
Normal file
@ -0,0 +1,74 @@
|
||||
/*
|
||||
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.
|
||||
*/ "use strict";
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
const _vm = /*#__PURE__*/ _interop_require_default(require("vm"));
|
||||
const _index = require("./index");
|
||||
const _options = require("./options");
|
||||
function _interop_require_default(obj) {
|
||||
return obj && obj.__esModule ? obj : {
|
||||
default: obj
|
||||
};
|
||||
}
|
||||
// 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.default;
|
||||
function getJestConfig(jestConfig) {
|
||||
return "config" in jestConfig ? jestConfig.config : jestConfig;
|
||||
}
|
||||
function isEsm(isEsmProject, filename, jestConfig) {
|
||||
var _jestConfig_extensionsToTreatAsEsm;
|
||||
return /\.jsx?$/.test(filename) && isEsmProject || ((_jestConfig_extensionsToTreatAsEsm = jestConfig.extensionsToTreatAsEsm) == null ? void 0 : _jestConfig_extensionsToTreatAsEsm.some((ext)=>filename.endsWith(ext)));
|
||||
}
|
||||
const createTransformer = (inputOptions)=>({
|
||||
process (src, filename, jestOptions) {
|
||||
const jestConfig = getJestConfig(jestOptions);
|
||||
const swcTransformOpts = (0, _options.getJestSWCOptions)({
|
||||
isServer: jestConfig.testEnvironment === "node" || jestConfig.testEnvironment.includes("jest-environment-node"),
|
||||
filename,
|
||||
jsConfig: inputOptions == null ? void 0 : inputOptions.jsConfig,
|
||||
resolvedBaseUrl: inputOptions == null ? void 0 : inputOptions.resolvedBaseUrl,
|
||||
pagesDir: inputOptions == null ? void 0 : inputOptions.pagesDir,
|
||||
serverComponents: inputOptions == null ? void 0 : inputOptions.serverComponents,
|
||||
modularizeImports: inputOptions == null ? void 0 : inputOptions.modularizeImports,
|
||||
swcPlugins: inputOptions == null ? void 0 : inputOptions.swcPlugins,
|
||||
compilerOptions: inputOptions == null ? void 0 : inputOptions.compilerOptions,
|
||||
esm: isSupportEsm && isEsm(Boolean(inputOptions == null ? void 0 : inputOptions.isEsmProject), filename, jestConfig)
|
||||
});
|
||||
return (0, _index.transformSync)(src, {
|
||||
...swcTransformOpts,
|
||||
filename
|
||||
});
|
||||
}
|
||||
});
|
||||
module.exports = {
|
||||
createTransformer
|
||||
};
|
||||
|
||||
//# sourceMappingURL=jest-transformer.js.map
|
||||
1
node_modules/next/dist/build/swc/jest-transformer.js.map
generated
vendored
Normal file
1
node_modules/next/dist/build/swc/jest-transformer.js.map
generated
vendored
Normal file
@ -0,0 +1 @@
|
||||
{"version":3,"sources":["../../../src/build/swc/jest-transformer.ts"],"names":["isSupportEsm","vm","getJestConfig","jestConfig","config","isEsm","isEsmProject","filename","test","extensionsToTreatAsEsm","some","ext","endsWith","createTransformer","inputOptions","process","src","jestOptions","swcTransformOpts","getJestSWCOptions","isServer","testEnvironment","includes","jsConfig","resolvedBaseUrl","pagesDir","serverComponents","modularizeImports","swcPlugins","compilerOptions","esm","Boolean","transformSync","module","exports"],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;AA0BA;;;;2DAEe;uBACe;yBACI;;;;;;AAsBlC,6FAA6F;AAC7F,mDAAmD;AACnD,MAAMA,eAAe,YAAYC,WAAE;AAEnC,SAASC,cACPC,UAAmD;IAEnD,OAAO,YAAYA,aAEfA,WAAWC,MAAM,GAEhBD;AACP;AAEA,SAASE,MACPC,YAAqB,EACrBC,QAAgB,EAChBJ,UAAgC;QAI9BA;IAFF,OACE,AAAC,UAAUK,IAAI,CAACD,aAAaD,kBAC7BH,qCAAAA,WAAWM,sBAAsB,qBAAjCN,mCAAmCO,IAAI,CAAC,CAACC,MACvCJ,SAASK,QAAQ,CAACD;AAGxB;AAEA,MAAME,oBAGF,CAACC,eAAkB,CAAA;QACrBC,SAAQC,GAAG,EAAET,QAAQ,EAAEU,WAAW;YAChC,MAAMd,aAAaD,cAAce;YAEjC,MAAMC,mBAAmBC,IAAAA,0BAAiB,EAAC;gBACzCC,UACEjB,WAAWkB,eAAe,KAAK,UAC/BlB,WAAWkB,eAAe,CAACC,QAAQ,CAAC;gBACtCf;gBACAgB,QAAQ,EAAET,gCAAAA,aAAcS,QAAQ;gBAChCC,eAAe,EAAEV,gCAAAA,aAAcU,eAAe;gBAC9CC,QAAQ,EAAEX,gCAAAA,aAAcW,QAAQ;gBAChCC,gBAAgB,EAAEZ,gCAAAA,aAAcY,gBAAgB;gBAChDC,iBAAiB,EAAEb,gCAAAA,aAAca,iBAAiB;gBAClDC,UAAU,EAAEd,gCAAAA,aAAcc,UAAU;gBACpCC,eAAe,EAAEf,gCAAAA,aAAce,eAAe;gBAC9CC,KACE9B,gBACAK,MAAM0B,QAAQjB,gCAAAA,aAAcR,YAAY,GAAGC,UAAUJ;YACzD;YAEA,OAAO6B,IAAAA,oBAAa,EAAChB,KAAK;gBAAE,GAAGE,gBAAgB;gBAAEX;YAAS;QAC5D;IACF,CAAA;AAEA0B,OAAOC,OAAO,GAAG;IAAErB;AAAkB"}
|
||||
148
node_modules/next/dist/build/swc/options.d.ts
generated
vendored
Normal file
148
node_modules/next/dist/build/swc/options.d.ts
generated
vendored
Normal file
@ -0,0 +1,148 @@
|
||||
import { type WebpackLayerName } from '../../lib/constants';
|
||||
import type { NextConfig, ExperimentalConfig } from '../../server/config-shared';
|
||||
import type { ResolvedBaseUrl } from '../load-jsconfig';
|
||||
export declare function getParserOptions({ filename, jsConfig, ...rest }: any): any;
|
||||
export declare function getJestSWCOptions({ isServer, filename, esm, modularizeImports, swcPlugins, compilerOptions, jsConfig, resolvedBaseUrl, pagesDir, }: {
|
||||
isServer: boolean;
|
||||
filename: string;
|
||||
esm: boolean;
|
||||
modularizeImports?: NextConfig['modularizeImports'];
|
||||
swcPlugins: ExperimentalConfig['swcPlugins'];
|
||||
compilerOptions: NextConfig['compiler'];
|
||||
jsConfig: any;
|
||||
resolvedBaseUrl?: ResolvedBaseUrl;
|
||||
pagesDir?: string;
|
||||
serverComponents?: boolean;
|
||||
}): {
|
||||
env: {
|
||||
targets: {
|
||||
node: string;
|
||||
};
|
||||
};
|
||||
module: {
|
||||
type: string;
|
||||
};
|
||||
disableNextSsg: boolean;
|
||||
disablePageConfig: boolean;
|
||||
pagesDir: string | undefined;
|
||||
serverComponents: {
|
||||
isReactServerLayer: boolean;
|
||||
} | undefined;
|
||||
serverActions: {
|
||||
enabled: boolean;
|
||||
isReactServerLayer: boolean;
|
||||
hashSalt: string;
|
||||
} | undefined;
|
||||
preferEsm: boolean;
|
||||
emotion?: {
|
||||
importMap?: {
|
||||
[importName: string]: {
|
||||
[exportName: string]: {
|
||||
canonicalImport?: [string, string] | undefined;
|
||||
styledBaseImport?: [string, string] | undefined;
|
||||
};
|
||||
};
|
||||
} | undefined;
|
||||
labelFormat?: string | undefined;
|
||||
sourcemap: boolean;
|
||||
enabled: boolean;
|
||||
autoLabel: boolean;
|
||||
} | null | undefined;
|
||||
styledComponents?: {
|
||||
displayName: boolean;
|
||||
topLevelImportPaths?: string[] | undefined;
|
||||
ssr?: boolean | undefined;
|
||||
fileName?: boolean | undefined;
|
||||
meaninglessFileNames?: string[] | undefined;
|
||||
minify?: boolean | undefined;
|
||||
transpileTemplateLiterals?: boolean | undefined;
|
||||
namespace?: string | undefined;
|
||||
pure?: boolean | undefined;
|
||||
cssProp?: boolean | undefined;
|
||||
} | null | undefined;
|
||||
jsc: {
|
||||
externalHelpers: boolean;
|
||||
parser: any;
|
||||
experimental: {
|
||||
keepImportAttributes: boolean;
|
||||
emitAssertForImportAttributes: boolean;
|
||||
plugins: any[][];
|
||||
cacheRoot: string | undefined;
|
||||
};
|
||||
transform: {
|
||||
legacyDecorator: boolean;
|
||||
decoratorMetadata: boolean;
|
||||
useDefineForClassFields: boolean;
|
||||
react: {
|
||||
importSource: any;
|
||||
runtime: string;
|
||||
pragmaFrag: string;
|
||||
throwIfNamespace: boolean;
|
||||
development: boolean;
|
||||
useBuiltins: boolean;
|
||||
refresh: boolean;
|
||||
};
|
||||
optimizer: {
|
||||
simplify: boolean;
|
||||
globals: {
|
||||
typeofs: {
|
||||
window: string;
|
||||
};
|
||||
envs: {
|
||||
NODE_ENV: string;
|
||||
};
|
||||
} | null;
|
||||
};
|
||||
regenerator: {
|
||||
importPath: string;
|
||||
};
|
||||
hidden?: {
|
||||
jest: boolean;
|
||||
} | undefined;
|
||||
};
|
||||
baseUrl?: string | undefined;
|
||||
paths?: any;
|
||||
};
|
||||
sourceMaps: string | undefined;
|
||||
removeConsole: boolean | {
|
||||
exclude?: string[] | undefined;
|
||||
} | undefined;
|
||||
reactRemoveProperties: boolean | {
|
||||
properties?: string[] | undefined;
|
||||
} | undefined;
|
||||
modularizeImports: {
|
||||
[k: string]: {
|
||||
transform: string | string[][];
|
||||
preventFullImport?: boolean | undefined;
|
||||
skipDefaultConversion?: boolean | undefined;
|
||||
};
|
||||
} | undefined;
|
||||
relay: {
|
||||
src: string;
|
||||
artifactDirectory?: string | undefined;
|
||||
language?: "flow" | "typescript" | "javascript" | undefined;
|
||||
eagerEsModules?: boolean | undefined;
|
||||
} | undefined;
|
||||
styledJsx: {};
|
||||
};
|
||||
export declare function getLoaderSWCOptions({ filename, development, isServer, pagesDir, appDir, isPageFile, hasReactRefresh, modularizeImports, optimizeServerReact, optimizePackageImports, swcPlugins, compilerOptions, jsConfig, supportedBrowsers, swcCacheDir, relativeFilePathFromRoot, serverComponents, bundleLayer, esm, }: {
|
||||
filename: string;
|
||||
development: boolean;
|
||||
isServer: boolean;
|
||||
pagesDir?: string;
|
||||
appDir?: string;
|
||||
isPageFile: boolean;
|
||||
hasReactRefresh: boolean;
|
||||
optimizeServerReact?: boolean;
|
||||
modularizeImports: NextConfig['modularizeImports'];
|
||||
optimizePackageImports?: NonNullable<NextConfig['experimental']>['optimizePackageImports'];
|
||||
swcPlugins: ExperimentalConfig['swcPlugins'];
|
||||
compilerOptions: NextConfig['compiler'];
|
||||
jsConfig: any;
|
||||
supportedBrowsers: string[] | undefined;
|
||||
swcCacheDir: string;
|
||||
relativeFilePathFromRoot: string;
|
||||
esm?: boolean;
|
||||
serverComponents?: boolean;
|
||||
bundleLayer?: WebpackLayerName;
|
||||
}): any;
|
||||
357
node_modules/next/dist/build/swc/options.js
generated
vendored
Normal file
357
node_modules/next/dist/build/swc/options.js
generated
vendored
Normal file
@ -0,0 +1,357 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
0 && (module.exports = {
|
||||
getJestSWCOptions: null,
|
||||
getLoaderSWCOptions: null,
|
||||
getParserOptions: null
|
||||
});
|
||||
function _export(target, all) {
|
||||
for(var name in all)Object.defineProperty(target, name, {
|
||||
enumerable: true,
|
||||
get: all[name]
|
||||
});
|
||||
}
|
||||
_export(exports, {
|
||||
getJestSWCOptions: function() {
|
||||
return getJestSWCOptions;
|
||||
},
|
||||
getLoaderSWCOptions: function() {
|
||||
return getLoaderSWCOptions;
|
||||
},
|
||||
getParserOptions: function() {
|
||||
return getParserOptions;
|
||||
}
|
||||
});
|
||||
const _constants = require("../../lib/constants");
|
||||
const nextDistPath = /(next[\\/]dist[\\/]shared[\\/]lib)|(next[\\/]dist[\\/]client)|(next[\\/]dist[\\/]pages)/;
|
||||
const nodeModulesPath = /[\\/]node_modules[\\/]/;
|
||||
const regeneratorRuntimePath = require.resolve("next/dist/compiled/regenerator-runtime");
|
||||
function isTypeScriptFile(filename) {
|
||||
return filename.endsWith(".ts") || filename.endsWith(".tsx");
|
||||
}
|
||||
function isCommonJSFile(filename) {
|
||||
return filename.endsWith(".cjs");
|
||||
}
|
||||
// Ensure Next.js internals and .cjs files are output as CJS modules,
|
||||
// By default all modules are output as ESM or will treated as CJS if next-swc/auto-cjs plugin detects file is CJS.
|
||||
function shouldOutputCommonJs(filename) {
|
||||
return isCommonJSFile(filename) || nextDistPath.test(filename);
|
||||
}
|
||||
function getParserOptions({ filename, jsConfig, ...rest }) {
|
||||
var _jsConfig_compilerOptions;
|
||||
const isTSFile = filename.endsWith(".ts");
|
||||
const hasTsSyntax = isTypeScriptFile(filename);
|
||||
const enableDecorators = Boolean(jsConfig == null ? void 0 : (_jsConfig_compilerOptions = jsConfig.compilerOptions) == null ? void 0 : _jsConfig_compilerOptions.experimentalDecorators);
|
||||
return {
|
||||
...rest,
|
||||
syntax: hasTsSyntax ? "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.
|
||||
[hasTsSyntax ? "tsx" : "jsx"]: !isTSFile,
|
||||
importAssertions: true
|
||||
};
|
||||
}
|
||||
function getBaseSWCOptions({ filename, jest, development, hasReactRefresh, globalWindow, esm, modularizeImports, swcPlugins, compilerOptions, resolvedBaseUrl, jsConfig, swcCacheDir, serverComponents, bundleLayer }) {
|
||||
var _jsConfig_compilerOptions, _jsConfig_compilerOptions1, _jsConfig_compilerOptions2, _jsConfig_compilerOptions3, _jsConfig_compilerOptions4;
|
||||
const isReactServerLayer = bundleLayer === _constants.WEBPACK_LAYERS.reactServerComponents;
|
||||
const parserConfig = getParserOptions({
|
||||
filename,
|
||||
jsConfig
|
||||
});
|
||||
const paths = jsConfig == null ? void 0 : (_jsConfig_compilerOptions = jsConfig.compilerOptions) == null ? void 0 : _jsConfig_compilerOptions.paths;
|
||||
const enableDecorators = Boolean(jsConfig == null ? void 0 : (_jsConfig_compilerOptions1 = jsConfig.compilerOptions) == null ? void 0 : _jsConfig_compilerOptions1.experimentalDecorators);
|
||||
const emitDecoratorMetadata = Boolean(jsConfig == null ? void 0 : (_jsConfig_compilerOptions2 = jsConfig.compilerOptions) == null ? void 0 : _jsConfig_compilerOptions2.emitDecoratorMetadata);
|
||||
const useDefineForClassFields = Boolean(jsConfig == null ? void 0 : (_jsConfig_compilerOptions3 = jsConfig.compilerOptions) == null ? void 0 : _jsConfig_compilerOptions3.useDefineForClassFields);
|
||||
const plugins = (swcPlugins ?? []).filter(Array.isArray).map(([name, options])=>[
|
||||
require.resolve(name),
|
||||
options
|
||||
]);
|
||||
return {
|
||||
jsc: {
|
||||
...resolvedBaseUrl && paths ? {
|
||||
baseUrl: resolvedBaseUrl.baseUrl,
|
||||
paths
|
||||
} : {},
|
||||
externalHelpers: !process.versions.pnp && !jest,
|
||||
parser: parserConfig,
|
||||
experimental: {
|
||||
keepImportAttributes: true,
|
||||
emitAssertForImportAttributes: 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 : (_jsConfig_compilerOptions4 = jsConfig.compilerOptions) == null ? void 0 : _jsConfig_compilerOptions4.jsxImportSource) ?? ((compilerOptions == null ? void 0 : compilerOptions.emotion) && !isReactServerLayer ? "@emotion/react" : "react"),
|
||||
runtime: "automatic",
|
||||
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: compilerOptions == null ? void 0 : compilerOptions.removeConsole,
|
||||
// disable "reactRemoveProperties" when "jest" is true
|
||||
// otherwise the setting from next.config.js will be used
|
||||
reactRemoveProperties: jest ? false : compilerOptions == null ? void 0 : compilerOptions.reactRemoveProperties,
|
||||
// Map the k-v map to an array of pairs.
|
||||
modularizeImports: modularizeImports ? Object.fromEntries(Object.entries(modularizeImports).map(([mod, config])=>[
|
||||
mod,
|
||||
{
|
||||
...config,
|
||||
transform: typeof config.transform === "string" ? config.transform : Object.entries(config.transform).map(([key, value])=>[
|
||||
key,
|
||||
value
|
||||
])
|
||||
}
|
||||
])) : undefined,
|
||||
relay: compilerOptions == null ? void 0 : compilerOptions.relay,
|
||||
// Always transform styled-jsx and error when `client-only` condition is triggered
|
||||
styledJsx: {},
|
||||
// Disable css-in-js libs (without client-only integration) transform on server layer for server components
|
||||
...!isReactServerLayer && {
|
||||
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
||||
emotion: getEmotionOptions(compilerOptions == null ? void 0 : compilerOptions.emotion, development),
|
||||
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
||||
styledComponents: getStyledComponentsOptions(compilerOptions == null ? void 0 : compilerOptions.styledComponents, development)
|
||||
},
|
||||
serverComponents: serverComponents && !jest ? {
|
||||
isReactServerLayer
|
||||
} : undefined,
|
||||
serverActions: serverComponents && !jest ? {
|
||||
// always enable server actions
|
||||
// TODO: remove this option
|
||||
enabled: true,
|
||||
isReactServerLayer,
|
||||
hashSalt: ""
|
||||
} : undefined,
|
||||
// For app router we prefer to bundle ESM,
|
||||
// On server side of pages router we prefer CJS.
|
||||
preferEsm: esm
|
||||
};
|
||||
}
|
||||
function getStyledComponentsOptions(styledComponentsConfig, development) {
|
||||
if (!styledComponentsConfig) {
|
||||
return null;
|
||||
} else if (typeof styledComponentsConfig === "object") {
|
||||
return {
|
||||
...styledComponentsConfig,
|
||||
displayName: styledComponentsConfig.displayName ?? Boolean(development)
|
||||
};
|
||||
} else {
|
||||
return {
|
||||
displayName: Boolean(development)
|
||||
};
|
||||
}
|
||||
}
|
||||
function getEmotionOptions(emotionConfig, development) {
|
||||
if (!emotionConfig) {
|
||||
return null;
|
||||
}
|
||||
let autoLabel = !!development;
|
||||
switch(typeof emotionConfig === "object" && emotionConfig.autoLabel){
|
||||
case "never":
|
||||
autoLabel = false;
|
||||
break;
|
||||
case "always":
|
||||
autoLabel = true;
|
||||
break;
|
||||
case "dev-only":
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return {
|
||||
enabled: true,
|
||||
autoLabel,
|
||||
sourcemap: development,
|
||||
...typeof emotionConfig === "object" && {
|
||||
importMap: emotionConfig.importMap,
|
||||
labelFormat: emotionConfig.labelFormat,
|
||||
sourcemap: development && emotionConfig.sourceMap
|
||||
}
|
||||
};
|
||||
}
|
||||
function getJestSWCOptions({ isServer, filename, esm, modularizeImports, swcPlugins, compilerOptions, jsConfig, resolvedBaseUrl, pagesDir }) {
|
||||
let baseOptions = getBaseSWCOptions({
|
||||
filename,
|
||||
jest: true,
|
||||
development: false,
|
||||
hasReactRefresh: false,
|
||||
globalWindow: !isServer,
|
||||
modularizeImports,
|
||||
swcPlugins,
|
||||
compilerOptions,
|
||||
jsConfig,
|
||||
resolvedBaseUrl,
|
||||
esm,
|
||||
// Don't apply server layer transformations for Jest
|
||||
// Disable server / client graph assertions for Jest
|
||||
bundleLayer: undefined,
|
||||
serverComponents: false
|
||||
});
|
||||
const useCjsModules = shouldOutputCommonJs(filename);
|
||||
return {
|
||||
...baseOptions,
|
||||
env: {
|
||||
targets: {
|
||||
// Targets the current version of Node.js
|
||||
node: process.versions.node
|
||||
}
|
||||
},
|
||||
module: {
|
||||
type: esm && !useCjsModules ? "es6" : "commonjs"
|
||||
},
|
||||
disableNextSsg: true,
|
||||
disablePageConfig: true,
|
||||
pagesDir
|
||||
};
|
||||
}
|
||||
function getLoaderSWCOptions({ // This is not passed yet as "paths" resolving is handled by webpack currently.
|
||||
// resolvedBaseUrl,
|
||||
filename, development, isServer, pagesDir, appDir, isPageFile, hasReactRefresh, modularizeImports, optimizeServerReact, optimizePackageImports, swcPlugins, compilerOptions, jsConfig, supportedBrowsers, swcCacheDir, relativeFilePathFromRoot, serverComponents, bundleLayer, esm }) {
|
||||
let baseOptions = getBaseSWCOptions({
|
||||
filename,
|
||||
development,
|
||||
globalWindow: !isServer,
|
||||
hasReactRefresh,
|
||||
modularizeImports,
|
||||
swcPlugins,
|
||||
compilerOptions,
|
||||
jsConfig,
|
||||
// resolvedBaseUrl,
|
||||
swcCacheDir,
|
||||
bundleLayer,
|
||||
serverComponents,
|
||||
esm: !!esm
|
||||
});
|
||||
baseOptions.fontLoaders = {
|
||||
fontLoaders: [
|
||||
"next/font/local",
|
||||
"next/font/google",
|
||||
// TODO: remove this in the next major version
|
||||
"@next/font/local",
|
||||
"@next/font/google"
|
||||
],
|
||||
relativeFilePathFromRoot
|
||||
};
|
||||
baseOptions.cjsRequireOptimizer = {
|
||||
packages: {
|
||||
"next/server": {
|
||||
transforms: {
|
||||
NextRequest: "next/dist/server/web/spec-extension/request",
|
||||
NextResponse: "next/dist/server/web/spec-extension/response",
|
||||
ImageResponse: "next/dist/server/web/spec-extension/image-response",
|
||||
userAgentFromString: "next/dist/server/web/spec-extension/user-agent",
|
||||
userAgent: "next/dist/server/web/spec-extension/user-agent"
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
if (optimizeServerReact && isServer && !development) {
|
||||
baseOptions.optimizeServerReact = {
|
||||
optimize_use_state: false
|
||||
};
|
||||
}
|
||||
// Modularize import optimization for barrel files
|
||||
if (optimizePackageImports) {
|
||||
baseOptions.autoModularizeImports = {
|
||||
packages: optimizePackageImports
|
||||
};
|
||||
}
|
||||
const isNodeModules = nodeModulesPath.test(filename);
|
||||
const isAppBrowserLayer = bundleLayer === _constants.WEBPACK_LAYERS.appPagesBrowser;
|
||||
const moduleResolutionConfig = shouldOutputCommonJs(filename) ? {
|
||||
module: {
|
||||
type: "commonjs"
|
||||
}
|
||||
} : {};
|
||||
let options;
|
||||
if (isServer) {
|
||||
options = {
|
||||
...baseOptions,
|
||||
...moduleResolutionConfig,
|
||||
// Disables getStaticProps/getServerSideProps tree shaking on the server compilation for pages
|
||||
disableNextSsg: true,
|
||||
disablePageConfig: true,
|
||||
isDevelopment: development,
|
||||
isServerCompiler: isServer,
|
||||
pagesDir,
|
||||
appDir,
|
||||
preferEsm: !!esm,
|
||||
isPageFile,
|
||||
env: {
|
||||
targets: {
|
||||
// Targets the current version of Node.js
|
||||
node: process.versions.node
|
||||
}
|
||||
}
|
||||
};
|
||||
} else {
|
||||
options = {
|
||||
...baseOptions,
|
||||
...moduleResolutionConfig,
|
||||
disableNextSsg: !isPageFile,
|
||||
isDevelopment: development,
|
||||
isServerCompiler: isServer,
|
||||
pagesDir,
|
||||
appDir,
|
||||
isPageFile,
|
||||
...supportedBrowsers && supportedBrowsers.length > 0 ? {
|
||||
env: {
|
||||
targets: supportedBrowsers
|
||||
}
|
||||
} : {}
|
||||
};
|
||||
if (!options.env) {
|
||||
// Matches default @babel/preset-env behavior
|
||||
options.jsc.target = "es5";
|
||||
}
|
||||
}
|
||||
// For node_modules in app browser layer, we don't need to do any server side transformation.
|
||||
// Only keep server actions transform to discover server actions from client components.
|
||||
if (isAppBrowserLayer && isNodeModules) {
|
||||
var _options_jsc_transform_optimizer_globals;
|
||||
options.disableNextSsg = true;
|
||||
options.disablePageConfig = true;
|
||||
options.isPageFile = false;
|
||||
options.optimizeServerReact = undefined;
|
||||
options.cjsRequireOptimizer = undefined;
|
||||
// Disable optimizer for node_modules in app browser layer, to avoid unnecessary replacement.
|
||||
// e.g. typeof window could result differently in js worker or browser.
|
||||
if ((_options_jsc_transform_optimizer_globals = options.jsc.transform.optimizer.globals) == null ? void 0 : _options_jsc_transform_optimizer_globals.typeofs) {
|
||||
delete options.jsc.transform.optimizer.globals.typeofs.window;
|
||||
}
|
||||
}
|
||||
return options;
|
||||
}
|
||||
|
||||
//# sourceMappingURL=options.js.map
|
||||
1
node_modules/next/dist/build/swc/options.js.map
generated
vendored
Normal file
1
node_modules/next/dist/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