@wyw-in-js/nextjs 1.1.0 → 2.0.0-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +16 -5
- package/esm/index.mjs +269 -349
- package/esm/index.mjs.map +1 -1
- package/package.json +13 -13
- package/types/index.d.ts +2 -1
- package/types/index.js +38 -95
- package/lib/index.js +0 -394
- package/lib/index.js.map +0 -1
package/esm/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":["fs","path","DEFAULT_EXTENSION","DEFAULT_TURBO_RULE_KEYS","DEFAULT_REACT_IMPORT_OVERRIDES","react","mock","PLACEHOLDER_EXTENSIONS","Set","PLACEHOLDER_IGNORED_DIRS","isObject","value","isUseLoaderObject","item","loader","normalizeUseItems","use","list","Array","isArray","filter","Boolean","length","getLoaderName","isWywLoaderPath","includes","test","convertLoaderRuleToUseRule","rule","wywLoaderItem","alreadyInjected","isNextJsTranspileRule","some","needle","options","nextRule","Object","assign","undefined","traverseRules","rules","visitor","oneOf","escapeRegExp","replace","isPlainObject","proto","getPrototypeOf","prototype","assertNoFunctions","name","queue","seen","current","shift","Error","has","add","forEach","idx","push","entries","key","createWywCssModuleRule","baseRule","extensionSuffix","patchedUse","map","itemOptions","modules","nextModules","mode","getLocalIdent","_context","_localIdentName","localName","sideEffects","RegExp","ensureWywCssModuleRules","config","module","expectedTestSource","alreadyPresent","candidate","source","candidateRule","isModuleCssRule","hasCssLoader","splice","injectWywLoader","nextOptions","wywNext","require","resolve","nextBabelPreset","paths","process","cwd","extension","loaderOptions","babelOptions","presets","userImportOverrides","importOverrides","cssImport","sourceMap","dev","loaders","l","ensureTurbopackCssPlaceholders","projectRoot","dir","pop","readdirSync","withFileTypes","entry","entryPath","join","isDirectory","isFile","shouldIgnore","startsWith","endsWith","ext","extname","baseName","basename","cssFilePath","dirname","writeFileSync","flag","err","code","shouldUseTurbopackConfig","nextConfig","explicit","turbopack","pkgPath","pkg","version","major","Number","parseInt","split","isFinite","injectWywTurbopackRules","userOptions","turbopackLoaderOptions","env","NODE_ENV","useTurbopackConfig","isNextBuild","argv","isWebpackBuild","ruleValue","condition","all","not","wywRules","fromEntries","turbopackConfig","userTurbopack","userRules","userExperimental","experimental","userTurbo","turbo","withWyw","userWebpack","webpack","resolvedConfig"],"sources":["../src/index.ts"],"sourcesContent":["import fs from 'fs';\nimport path from 'path';\n\nimport type { LoaderOptions as WywWebpackLoaderOptions } from '@wyw-in-js/webpack-loader';\nimport type { NextConfig } from 'next';\nimport type { Configuration, RuleSetRule, RuleSetUseItem } from 'webpack';\n\nconst DEFAULT_EXTENSION = '.wyw-in-js.module.css';\n\nconst DEFAULT_TURBO_RULE_KEYS = ['*.js', '*.jsx', '*.ts', '*.tsx'];\n\nconst DEFAULT_REACT_IMPORT_OVERRIDES = {\n react: { mock: 'react' },\n 'react/jsx-runtime': { mock: 'react/jsx-runtime' },\n 'react/jsx-dev-runtime': { mock: 'react/jsx-dev-runtime' },\n} satisfies WywWebpackLoaderOptions['importOverrides'];\n\nconst PLACEHOLDER_EXTENSIONS = new Set(['.js', '.jsx', '.ts', '.tsx']);\nconst PLACEHOLDER_IGNORED_DIRS = new Set([\n '.git',\n '.next',\n '.turbo',\n 'node_modules',\n]);\n\nexport type WywNextPluginOptions = {\n loaderOptions?: Omit<WywWebpackLoaderOptions, 'extension' | 'sourceMap'> &\n Partial<Pick<WywWebpackLoaderOptions, 'extension' | 'sourceMap'>>;\n turbopackLoaderOptions?: Record<string, unknown>;\n};\n\ntype NextWebpackConfigFn = NonNullable<NextConfig['webpack']>;\ntype NextWebpackOptions = Parameters<NextWebpackConfigFn>[1];\n\nfunction isObject(value: unknown): value is Record<string, unknown> {\n return typeof value === 'object' && value !== null;\n}\n\nfunction isUseLoaderObject(\n item: RuleSetUseItem\n): item is Exclude<RuleSetUseItem, string> & { loader: string } {\n return (\n isObject(item) &&\n typeof (item as Record<string, unknown>).loader === 'string'\n );\n}\n\nfunction normalizeUseItems(use: RuleSetRule['use']): RuleSetUseItem[] | null {\n if (!use) return null;\n if (typeof use === 'function') return null;\n\n const list = (Array.isArray(use) ? use : [use]).filter(Boolean);\n return list.length ? (list as RuleSetUseItem[]) : null;\n}\n\nfunction getLoaderName(item: RuleSetUseItem): string {\n if (typeof item === 'string') return item;\n if (isUseLoaderObject(item)) return item.loader;\n return '';\n}\n\nfunction isWywLoaderPath(loader: string) {\n return (\n loader.includes('@wyw-in-js/webpack-loader') ||\n /[\\\\/]webpack-loader[\\\\/]/.test(loader)\n );\n}\n\nfunction convertLoaderRuleToUseRule(\n rule: RuleSetRule,\n wywLoaderItem: RuleSetUseItem\n) {\n const { loader } = rule as { loader?: unknown };\n if (typeof loader !== 'string') return;\n\n const alreadyInjected = isWywLoaderPath(loader);\n if (alreadyInjected) return;\n\n const isNextJsTranspileRule = [\n 'next-swc-loader',\n 'next-babel-loader',\n 'babel-loader',\n ].some((needle) => loader.includes(needle));\n if (!isNextJsTranspileRule) return;\n\n const { options } = rule as { options?: unknown };\n\n const nextRule = rule as RuleSetRule & {\n loader?: unknown;\n options?: unknown;\n };\n\n delete nextRule.loader;\n delete nextRule.options;\n\n // Loader order is right-to-left. We want WyW to run first, so it should be last.\n Object.assign(nextRule, {\n use: [\n { loader, ...(options !== undefined ? { options } : {}) },\n wywLoaderItem,\n ],\n });\n}\n\nfunction traverseRules(rules: unknown[], visitor: (rule: RuleSetRule) => void) {\n for (const rule of rules) {\n if (rule && typeof rule === 'object') {\n visitor(rule as RuleSetRule);\n\n if (Array.isArray((rule as RuleSetRule).oneOf)) {\n traverseRules((rule as RuleSetRule).oneOf!, visitor);\n }\n if (Array.isArray((rule as RuleSetRule).rules)) {\n traverseRules((rule as RuleSetRule).rules!, visitor);\n }\n }\n }\n}\n\nfunction escapeRegExp(value: string) {\n return value.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&');\n}\n\nfunction isPlainObject(value: unknown): value is Record<string, unknown> {\n if (!isObject(value)) return false;\n const proto = Object.getPrototypeOf(value);\n return proto === Object.prototype || proto === null;\n}\n\nfunction assertNoFunctions(value: unknown, name: string) {\n const queue: Array<{ path: string; value: unknown }> = [\n { path: name, value },\n ];\n const seen = new Set<unknown>();\n\n while (queue.length) {\n const current = queue.shift()!;\n\n if (typeof current.value === 'function') {\n throw new Error(\n `${current.path} must be JSON-serializable (functions are not supported in Turbopack loader options). Use \"configFile\" to pass non-JSON config.`\n );\n }\n\n if (current.value === null) {\n // skip\n } else if (Array.isArray(current.value)) {\n if (!seen.has(current.value)) {\n seen.add(current.value);\n current.value.forEach((item, idx) =>\n queue.push({ path: `${current.path}[${idx}]`, value: item })\n );\n }\n } else if (isPlainObject(current.value)) {\n if (!seen.has(current.value)) {\n seen.add(current.value);\n Object.entries(current.value).forEach(([key, item]) =>\n queue.push({ path: `${current.path}.${key}`, value: item })\n );\n }\n }\n }\n}\n\nfunction createWywCssModuleRule(\n baseRule: RuleSetRule,\n extensionSuffix: string\n): RuleSetRule {\n const use = normalizeUseItems(baseRule.use) ?? [];\n\n const patchedUse = use.map((item) => {\n if (!isUseLoaderObject(item) || !item.loader.includes('css-loader')) {\n return item;\n }\n\n const itemOptions = (item as { options?: unknown }).options;\n if (!isObject(itemOptions)) {\n return item;\n }\n\n const { modules } = itemOptions as { modules?: unknown };\n if (!isObject(modules)) {\n return item;\n }\n\n const nextModules = {\n ...(modules as Record<string, unknown>),\n mode: 'global',\n getLocalIdent: (\n _context: unknown,\n _localIdentName: string,\n localName: string\n ) => localName,\n };\n\n return {\n ...item,\n options: {\n ...(itemOptions as Record<string, unknown>),\n modules: nextModules,\n },\n };\n });\n\n const nextRule: RuleSetRule = {\n ...baseRule,\n sideEffects: true,\n test: new RegExp(`${escapeRegExp(extensionSuffix)}$`),\n use: patchedUse,\n };\n\n return nextRule;\n}\n\nfunction ensureWywCssModuleRules(\n config: Configuration,\n extensionSuffix: string\n) {\n traverseRules(config.module?.rules ?? [], (rule) => {\n if (!Array.isArray(rule.oneOf) || rule.oneOf.length === 0) {\n return;\n }\n\n const expectedTestSource = `${escapeRegExp(extensionSuffix)}$`;\n\n const alreadyPresent = rule.oneOf.some((candidate) => {\n if (!candidate || typeof candidate !== 'object') return false;\n\n const { test } = candidate as RuleSetRule;\n return test instanceof RegExp && test.source === expectedTestSource;\n });\n\n if (alreadyPresent) {\n return;\n }\n\n const oneOf = rule.oneOf as unknown[];\n for (let idx = 0; idx < oneOf.length; idx += 1) {\n const candidate = oneOf[idx];\n if (candidate && typeof candidate === 'object') {\n const candidateRule = candidate as RuleSetRule;\n const { test } = candidateRule;\n\n const isModuleCssRule =\n test instanceof RegExp && test.source.includes('\\\\.module\\\\.css');\n\n if (isModuleCssRule) {\n const use = normalizeUseItems(candidateRule.use);\n if (use) {\n const hasCssLoader = use.some(\n (item) =>\n isUseLoaderObject(item) && item.loader.includes('css-loader')\n );\n if (hasCssLoader) {\n oneOf.splice(\n idx,\n 0,\n createWywCssModuleRule(candidateRule, extensionSuffix)\n );\n break;\n }\n }\n }\n }\n }\n });\n}\n\nfunction injectWywLoader(\n config: Configuration,\n nextOptions: NextWebpackOptions,\n wywNext: WywNextPluginOptions\n) {\n const loader = require.resolve('@wyw-in-js/webpack-loader');\n const nextBabelPreset = require.resolve('next/babel', {\n paths: [process.cwd()],\n });\n\n const extension = wywNext.loaderOptions?.extension ?? DEFAULT_EXTENSION;\n const babelOptions = wywNext.loaderOptions?.babelOptions ?? {\n presets: [nextBabelPreset],\n };\n\n const userImportOverrides = wywNext.loaderOptions?.importOverrides;\n const importOverrides = userImportOverrides\n ? { ...DEFAULT_REACT_IMPORT_OVERRIDES, ...userImportOverrides }\n : DEFAULT_REACT_IMPORT_OVERRIDES;\n\n const loaderOptions = {\n cssImport: 'import',\n ...wywNext.loaderOptions,\n babelOptions,\n extension,\n importOverrides,\n sourceMap: wywNext.loaderOptions?.sourceMap ?? nextOptions.dev,\n } satisfies WywWebpackLoaderOptions;\n\n const wywLoaderItem: RuleSetUseItem = {\n loader,\n options: loaderOptions,\n };\n\n traverseRules(config.module?.rules ?? [], (rule) => {\n convertLoaderRuleToUseRule(rule, wywLoaderItem);\n\n const use = normalizeUseItems(rule.use);\n if (!use) return;\n\n const loaders = use.map(getLoaderName);\n\n const alreadyInjected = loaders.some(\n (l) => l === loader || isWywLoaderPath(l)\n );\n if (alreadyInjected) return;\n\n const isNextJsTranspileRule = loaders.some((l) =>\n ['next-swc-loader', 'next-babel-loader', 'babel-loader'].some((needle) =>\n l.includes(needle)\n )\n );\n if (!isNextJsTranspileRule) return;\n\n // Loader order is right-to-left. We want WyW to run first, so it should be last.\n Object.assign(rule, { use: [...use, wywLoaderItem] });\n });\n\n ensureWywCssModuleRules(config, extension);\n}\n\nfunction ensureTurbopackCssPlaceholders(projectRoot: string) {\n const queue: string[] = [projectRoot];\n\n while (queue.length) {\n const dir = queue.pop()!;\n let entries: fs.Dirent[];\n\n try {\n entries = fs.readdirSync(dir, { withFileTypes: true });\n } catch {\n entries = [];\n }\n\n for (const entry of entries) {\n if (entry.name !== '.' && entry.name !== '..') {\n const entryPath = path.join(dir, entry.name);\n\n if (entry.isDirectory()) {\n if (!PLACEHOLDER_IGNORED_DIRS.has(entry.name)) {\n queue.push(entryPath);\n }\n } else if (entry.isFile()) {\n const shouldIgnore =\n entry.name.startsWith('middleware.') ||\n entry.name.endsWith('.d.ts');\n\n if (!shouldIgnore) {\n const ext = path.extname(entry.name);\n if (PLACEHOLDER_EXTENSIONS.has(ext)) {\n const baseName = path.basename(entry.name, ext);\n const cssFilePath = path.join(\n path.dirname(entryPath),\n `${baseName}${DEFAULT_EXTENSION}`\n );\n\n try {\n fs.writeFileSync(cssFilePath, '', { flag: 'wx' });\n } catch (err) {\n if ((err as NodeJS.ErrnoException).code !== 'EEXIST') {\n throw err;\n }\n }\n }\n }\n }\n }\n }\n }\n}\n\nfunction shouldUseTurbopackConfig(nextConfig: NextConfig) {\n const explicit = (nextConfig as unknown as Record<string, unknown>).turbopack;\n if (typeof explicit !== 'undefined') {\n return true;\n }\n\n try {\n const pkgPath = require.resolve('next/package.json', {\n paths: [process.cwd()],\n });\n const pkg = require(pkgPath) as { version?: unknown };\n const version = typeof pkg.version === 'string' ? pkg.version : '';\n const major = Number.parseInt(version.split('.')[0] ?? '', 10);\n return Number.isFinite(major) && major >= 16;\n } catch {\n return false;\n }\n}\n\nfunction injectWywTurbopackRules(\n nextConfig: NextConfig,\n wywNext: WywNextPluginOptions\n): NextConfig {\n const loader = require.resolve('@wyw-in-js/turbopack-loader');\n const nextBabelPreset = require.resolve('next/babel', {\n paths: [process.cwd()],\n });\n\n const userOptions = wywNext.turbopackLoaderOptions ?? {};\n\n assertNoFunctions(userOptions, 'turbopackLoaderOptions');\n\n const userImportOverrides = isPlainObject(userOptions.importOverrides)\n ? (userOptions.importOverrides as Record<string, unknown>)\n : undefined;\n\n const loaderOptions = {\n babelOptions: { presets: [nextBabelPreset] },\n sourceMap: process.env.NODE_ENV !== 'production',\n ...userOptions,\n importOverrides: userImportOverrides\n ? { ...DEFAULT_REACT_IMPORT_OVERRIDES, ...userImportOverrides }\n : DEFAULT_REACT_IMPORT_OVERRIDES,\n };\n\n const useTurbopackConfig = shouldUseTurbopackConfig(nextConfig);\n\n const isNextBuild = process.argv.includes('build');\n const isWebpackBuild = process.argv.includes('--webpack');\n\n if (\n useTurbopackConfig &&\n process.env.NODE_ENV === 'production' &&\n isNextBuild &&\n !isWebpackBuild\n ) {\n ensureTurbopackCssPlaceholders(process.cwd());\n }\n\n const ruleValue = useTurbopackConfig\n ? {\n loaders: [{ loader, options: loaderOptions }],\n condition: {\n all: [\n { not: 'foreign' },\n { not: { path: /(?:^|[\\\\/])middleware\\.[jt]sx?$/ } },\n ],\n },\n }\n : [{ loader, options: loaderOptions }];\n\n const wywRules = Object.fromEntries(\n DEFAULT_TURBO_RULE_KEYS.map((key) => [key, ruleValue])\n );\n\n if (useTurbopackConfig) {\n const turbopackConfig = (nextConfig as unknown as Record<string, unknown>)\n .turbopack;\n const userTurbopack = isPlainObject(turbopackConfig) ? turbopackConfig : {};\n\n const userRules = isPlainObject(userTurbopack.rules)\n ? (userTurbopack.rules as Record<string, unknown>)\n : {};\n\n return {\n ...nextConfig,\n turbopack: {\n ...userTurbopack,\n rules: {\n ...wywRules,\n ...userRules,\n },\n },\n } as NextConfig;\n }\n\n const userExperimental = isPlainObject(nextConfig.experimental)\n ? (nextConfig.experimental as Record<string, unknown>)\n : {};\n\n const userTurbo = isPlainObject(userExperimental.turbo)\n ? (userExperimental.turbo as Record<string, unknown>)\n : {};\n\n const userRules = isPlainObject(userTurbo.rules)\n ? (userTurbo.rules as Record<string, unknown>)\n : {};\n\n return {\n ...nextConfig,\n experimental: {\n ...userExperimental,\n turbo: {\n ...userTurbo,\n rules: {\n ...wywRules,\n ...userRules,\n },\n },\n },\n } as NextConfig;\n}\n\nexport function withWyw(\n nextConfig: NextConfig = {},\n wywNext: WywNextPluginOptions = {}\n): NextConfig {\n const userWebpack = nextConfig.webpack;\n\n return {\n ...injectWywTurbopackRules(nextConfig, wywNext),\n webpack(config: Configuration, options: NextWebpackOptions) {\n const resolvedConfig =\n typeof userWebpack === 'function'\n ? userWebpack(config, options)\n : config;\n\n injectWywLoader(resolvedConfig, options, wywNext);\n\n return resolvedConfig;\n },\n };\n}\n"],"mappings":"AAAA,OAAOA,EAAE,MAAM,IAAI;AACnB,OAAOC,IAAI,MAAM,MAAM;AAMvB,MAAMC,iBAAiB,GAAG,uBAAuB;AAEjD,MAAMC,uBAAuB,GAAG,CAAC,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC;AAElE,MAAMC,8BAA8B,GAAG;EACrCC,KAAK,EAAE;IAAEC,IAAI,EAAE;EAAQ,CAAC;EACxB,mBAAmB,EAAE;IAAEA,IAAI,EAAE;EAAoB,CAAC;EAClD,uBAAuB,EAAE;IAAEA,IAAI,EAAE;EAAwB;AAC3D,CAAsD;AAEtD,MAAMC,sBAAsB,GAAG,IAAIC,G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AAE;AAEN,SAAO;GACL,GAAG;GACH,WAAW;IACT,GAAG;IACH,OAAO;KACL,GAAG;KACH,GAAG;KACJ;IACF;GACF;;CAGH,MAAM,YAAY,cAAc,UAAU,MAAM,GAC3C,UAAU,QACX,EAAE;AAEN,QAAO;EACL,GAAG;EACH,cAAc;GACZ,GAAG;GACH,OAAO;IACL,GAAG;IACH,OAAO;KACL,GAAG;KACH,GAAG;KACJ;IACF;GACF;EACF;;AAGH,OAAO,SAAS,QACd,aAAyB,EAAE,EAC3B,UAAgC,EAAE,EACtB;CACZ,MAAM,cAAc,WAAW;AAE/B,QAAO;EACL,GAAG,wBAAwB,YAAY,QAAQ;EAC/C,QAAQ,QAAuB,SAA6B;GAC1D,MAAM,iBACJ,OAAO,gBAAgB,aACnB,YAAY,QAAQ,QAAQ,GAC5B;AAEN,mBAAgB,gBAAgB,SAAS,QAAQ;AAEjD,UAAO;;EAEV","names":[],"sources":["../src/index.ts"],"version":3,"sourcesContent":["import { createRequire } from 'module';\n\nimport {\n mergeOxcResolverAlias,\n toNativeResolverAlias,\n} from '@wyw-in-js/shared';\nimport type { LoaderOptions as WywTurbopackLoaderOptions } from '@wyw-in-js/turbopack-loader';\nimport type { LoaderOptions as WywWebpackLoaderOptions } from '@wyw-in-js/webpack-loader';\nimport type { NextConfig } from 'next';\nimport type { Configuration, RuleSetRule, RuleSetUseItem } from 'webpack';\n\nconst DEFAULT_EXTENSION = '.wyw-in-js.module.css';\n\nconst DEFAULT_TURBO_RULE_KEYS = ['*.js', '*.jsx', '*.ts', '*.tsx'];\n\nconst DEFAULT_REACT_IMPORT_OVERRIDES = {\n react: { mock: 'react' },\n 'react/jsx-runtime': { mock: 'react/jsx-runtime' },\n 'react/jsx-dev-runtime': { mock: 'react/jsx-dev-runtime' },\n} satisfies WywWebpackLoaderOptions['importOverrides'];\n\nconst nodeRequire = createRequire(import.meta.url);\n\nexport type WywNextPluginOptions = {\n loaderOptions?: Omit<WywWebpackLoaderOptions, 'extension' | 'sourceMap'> &\n Partial<Pick<WywWebpackLoaderOptions, 'extension' | 'sourceMap'>>;\n turbopackLoaderOptions?: Partial<WywTurbopackLoaderOptions>;\n};\n\ntype NextWebpackConfigFn = NonNullable<NextConfig['webpack']>;\ntype NextWebpackOptions = Parameters<NextWebpackConfigFn>[1];\n\nfunction isObject(value: unknown): value is Record<string, unknown> {\n return typeof value === 'object' && value !== null;\n}\n\nfunction isUseLoaderObject(\n item: RuleSetUseItem\n): item is Exclude<RuleSetUseItem, string> & { loader: string } {\n return (\n isObject(item) &&\n typeof (item as Record<string, unknown>).loader === 'string'\n );\n}\n\nfunction normalizeUseItems(use: RuleSetRule['use']): RuleSetUseItem[] | null {\n if (!use) return null;\n if (typeof use === 'function') return null;\n\n const list = (Array.isArray(use) ? use : [use]).filter(Boolean);\n return list.length ? (list as RuleSetUseItem[]) : null;\n}\n\nfunction getLoaderName(item: RuleSetUseItem): string {\n if (typeof item === 'string') return item;\n if (isUseLoaderObject(item)) return item.loader;\n return '';\n}\n\nfunction isWywLoaderPath(loader: string) {\n return (\n loader.includes('@wyw-in-js/webpack-loader') ||\n /[\\\\/]webpack-loader[\\\\/]/.test(loader)\n );\n}\n\nfunction convertLoaderRuleToUseRule(\n rule: RuleSetRule,\n wywLoaderItem: RuleSetUseItem\n) {\n const { loader } = rule as { loader?: unknown };\n if (typeof loader !== 'string') return;\n\n const alreadyInjected = isWywLoaderPath(loader);\n if (alreadyInjected) return;\n\n const isNextJsTranspileRule = [\n 'next-swc-loader',\n 'next-babel-loader',\n 'babel-loader',\n ].some((needle) => loader.includes(needle));\n if (!isNextJsTranspileRule) return;\n\n const { options } = rule as { options?: unknown };\n\n const nextRule = rule as RuleSetRule & {\n loader?: unknown;\n options?: unknown;\n };\n\n delete nextRule.loader;\n delete nextRule.options;\n\n // Loader order is right-to-left. We want WyW to run first, so it should be last.\n Object.assign(nextRule, {\n use: [\n { loader, ...(options !== undefined ? { options } : {}) },\n wywLoaderItem,\n ],\n });\n}\n\nfunction traverseRules(rules: unknown[], visitor: (rule: RuleSetRule) => void) {\n for (const rule of rules) {\n if (rule && typeof rule === 'object') {\n visitor(rule as RuleSetRule);\n\n if (Array.isArray((rule as RuleSetRule).oneOf)) {\n traverseRules((rule as RuleSetRule).oneOf!, visitor);\n }\n if (Array.isArray((rule as RuleSetRule).rules)) {\n traverseRules((rule as RuleSetRule).rules!, visitor);\n }\n }\n }\n}\n\nfunction escapeRegExp(value: string) {\n return value.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&');\n}\n\nfunction isPlainObject(value: unknown): value is Record<string, unknown> {\n if (!isObject(value)) return false;\n const proto = Object.getPrototypeOf(value);\n return proto === Object.prototype || proto === null;\n}\n\nfunction assertJsonSerializable(value: unknown, name: string) {\n const queue: Array<{ path: string; value: unknown }> = [\n { path: name, value },\n ];\n const seen = new Set<unknown>();\n\n while (queue.length) {\n const current = queue.shift()!;\n\n if (current.value === null) {\n // skip\n } else if (typeof current.value === 'undefined') {\n // skip\n } else if (\n typeof current.value === 'string' ||\n typeof current.value === 'number' ||\n typeof current.value === 'boolean'\n ) {\n // primitives are ok\n } else if (\n typeof current.value === 'function' ||\n typeof current.value === 'symbol' ||\n typeof current.value === 'bigint'\n ) {\n throw new Error(\n `${current.path} must be JSON-serializable (functions, symbols and bigint are not supported in Turbopack loader options). Use \"configFile\" to pass non-JSON config.`\n );\n } else if (Array.isArray(current.value)) {\n if (!seen.has(current.value)) {\n seen.add(current.value);\n current.value.forEach((item, idx) =>\n queue.push({ path: `${current.path}[${idx}]`, value: item })\n );\n }\n } else if (isPlainObject(current.value)) {\n if (!seen.has(current.value)) {\n seen.add(current.value);\n Object.entries(current.value).forEach(([key, item]) =>\n queue.push({ path: `${current.path}.${key}`, value: item })\n );\n }\n } else {\n throw new Error(\n `${current.path} must be JSON-serializable (only plain objects, arrays, and primitives are supported in Turbopack loader options). Use \"configFile\" to pass non-JSON config.`\n );\n }\n }\n}\n\nfunction createWywCssModuleRule(\n baseRule: RuleSetRule,\n extensionSuffix: string\n): RuleSetRule {\n const use = normalizeUseItems(baseRule.use) ?? [];\n\n const patchedUse = use.map((item) => {\n if (!isUseLoaderObject(item) || !item.loader.includes('css-loader')) {\n return item;\n }\n\n const itemOptions = (item as { options?: unknown }).options;\n if (!isObject(itemOptions)) {\n return item;\n }\n\n const { modules } = itemOptions as { modules?: unknown };\n if (!isObject(modules)) {\n return item;\n }\n\n const nextModules = {\n ...(modules as Record<string, unknown>),\n mode: 'global',\n getLocalIdent: (\n _context: unknown,\n _localIdentName: string,\n localName: string\n ) => localName,\n };\n\n return {\n ...item,\n options: {\n ...(itemOptions as Record<string, unknown>),\n modules: nextModules,\n },\n };\n });\n\n const nextRule: RuleSetRule = {\n ...baseRule,\n sideEffects: true,\n test: new RegExp(`${escapeRegExp(extensionSuffix)}$`),\n use: patchedUse,\n };\n\n return nextRule;\n}\n\nfunction ensureWywCssModuleRules(\n config: Configuration,\n extensionSuffix: string\n) {\n traverseRules(config.module?.rules ?? [], (rule) => {\n if (!Array.isArray(rule.oneOf) || rule.oneOf.length === 0) {\n return;\n }\n\n const expectedTestSource = `${escapeRegExp(extensionSuffix)}$`;\n\n const alreadyPresent = rule.oneOf.some((candidate) => {\n if (!candidate || typeof candidate !== 'object') return false;\n\n const { test } = candidate as RuleSetRule;\n return test instanceof RegExp && test.source === expectedTestSource;\n });\n\n if (alreadyPresent) {\n return;\n }\n\n const oneOf = rule.oneOf as unknown[];\n for (let idx = 0; idx < oneOf.length; idx += 1) {\n const candidate = oneOf[idx];\n if (candidate && typeof candidate === 'object') {\n const candidateRule = candidate as RuleSetRule;\n const { test } = candidateRule;\n\n const isModuleCssRule =\n test instanceof RegExp && test.source.includes('\\\\.module\\\\.css');\n\n if (isModuleCssRule) {\n const use = normalizeUseItems(candidateRule.use);\n if (use) {\n const hasCssLoader = use.some(\n (item) =>\n isUseLoaderObject(item) && item.loader.includes('css-loader')\n );\n if (hasCssLoader) {\n oneOf.splice(\n idx,\n 0,\n createWywCssModuleRule(candidateRule, extensionSuffix)\n );\n break;\n }\n }\n }\n }\n }\n });\n}\n\nfunction injectWywLoader(\n config: Configuration,\n nextOptions: NextWebpackOptions,\n wywNext: WywNextPluginOptions\n) {\n const loader = nodeRequire.resolve('@wyw-in-js/webpack-loader');\n\n const extension = wywNext.loaderOptions?.extension ?? DEFAULT_EXTENSION;\n\n const userImportOverrides = wywNext.loaderOptions?.importOverrides;\n const importOverrides = userImportOverrides\n ? { ...DEFAULT_REACT_IMPORT_OVERRIDES, ...userImportOverrides }\n : DEFAULT_REACT_IMPORT_OVERRIDES;\n\n const loaderOptions = {\n cssImport: 'import',\n ...wywNext.loaderOptions,\n extension,\n importOverrides,\n sourceMap: wywNext.loaderOptions?.sourceMap ?? nextOptions.dev,\n } satisfies WywWebpackLoaderOptions;\n\n const wywLoaderItem: RuleSetUseItem = {\n loader,\n options: loaderOptions,\n };\n\n traverseRules(config.module?.rules ?? [], (rule) => {\n convertLoaderRuleToUseRule(rule, wywLoaderItem);\n\n const use = normalizeUseItems(rule.use);\n if (!use) return;\n\n const loaders = use.map(getLoaderName);\n\n const alreadyInjected = loaders.some(\n (l) => l === loader || isWywLoaderPath(l)\n );\n if (alreadyInjected) return;\n\n const isNextJsTranspileRule = loaders.some((l) =>\n ['next-swc-loader', 'next-babel-loader', 'babel-loader'].some((needle) =>\n l.includes(needle)\n )\n );\n if (!isNextJsTranspileRule) return;\n\n // Loader order is right-to-left. We want WyW to run first, so it should be last.\n Object.assign(rule, { use: [...use, wywLoaderItem] });\n });\n\n ensureWywCssModuleRules(config, extension);\n}\n\nfunction shouldUseTurbopackConfig(nextConfig: NextConfig) {\n const explicit = (nextConfig as unknown as Record<string, unknown>).turbopack;\n if (typeof explicit !== 'undefined') {\n return true;\n }\n\n try {\n const pkgPath = nodeRequire.resolve('next/package.json', {\n paths: [process.cwd()],\n });\n const pkg = nodeRequire(pkgPath) as { version?: unknown };\n const version = typeof pkg.version === 'string' ? pkg.version : '';\n const major = Number.parseInt(version.split('.')[0] ?? '', 10);\n return Number.isFinite(major) && major >= 16;\n } catch {\n return false;\n }\n}\n\nfunction injectWywTurbopackRules(\n nextConfig: NextConfig,\n wywNext: WywNextPluginOptions\n): NextConfig {\n const loader = nodeRequire.resolve('@wyw-in-js/turbopack-loader');\n\n const userOptions = wywNext.turbopackLoaderOptions ?? {};\n\n assertJsonSerializable(userOptions, 'turbopackLoaderOptions');\n\n const turbopackConfig = (nextConfig as unknown as Record<string, unknown>)\n .turbopack;\n const userTurbopack = isPlainObject(turbopackConfig) ? turbopackConfig : {};\n const userExperimental = isPlainObject(nextConfig.experimental)\n ? (nextConfig.experimental as Record<string, unknown>)\n : {};\n const userTurbo = isPlainObject(userExperimental.turbo)\n ? (userExperimental.turbo as Record<string, unknown>)\n : {};\n\n const nativeResolverAlias = toNativeResolverAlias(\n userTurbopack.resolveAlias ?? userTurbo.resolveAlias\n );\n const oxcOptions = mergeOxcResolverAlias(\n userOptions.oxcOptions,\n nativeResolverAlias\n );\n\n const userImportOverrides = isPlainObject(userOptions.importOverrides)\n ? (userOptions.importOverrides as Record<string, unknown>)\n : undefined;\n\n const loaderOptions = {\n sourceMap: process.env.NODE_ENV !== 'production',\n ...userOptions,\n ...(oxcOptions ? { oxcOptions } : {}),\n importOverrides: userImportOverrides\n ? { ...DEFAULT_REACT_IMPORT_OVERRIDES, ...userImportOverrides }\n : DEFAULT_REACT_IMPORT_OVERRIDES,\n };\n\n const useTurbopackConfig = shouldUseTurbopackConfig(nextConfig);\n\n const ruleValue = useTurbopackConfig\n ? {\n loaders: [{ loader, options: loaderOptions }],\n condition: {\n all: [\n { not: 'foreign' },\n { not: { path: /(?:^|[\\\\/])middleware\\.[jt]sx?$/ } },\n ],\n },\n }\n : [{ loader, options: loaderOptions }];\n\n const wywRules = Object.fromEntries(\n DEFAULT_TURBO_RULE_KEYS.map((key) => [key, ruleValue])\n );\n\n if (useTurbopackConfig) {\n const userRules = isPlainObject(userTurbopack.rules)\n ? (userTurbopack.rules as Record<string, unknown>)\n : {};\n\n return {\n ...nextConfig,\n turbopack: {\n ...userTurbopack,\n rules: {\n ...wywRules,\n ...userRules,\n },\n },\n } as NextConfig;\n }\n\n const userRules = isPlainObject(userTurbo.rules)\n ? (userTurbo.rules as Record<string, unknown>)\n : {};\n\n return {\n ...nextConfig,\n experimental: {\n ...userExperimental,\n turbo: {\n ...userTurbo,\n rules: {\n ...wywRules,\n ...userRules,\n },\n },\n },\n } as NextConfig;\n}\n\nexport function withWyw(\n nextConfig: NextConfig = {},\n wywNext: WywNextPluginOptions = {}\n): NextConfig {\n const userWebpack = nextConfig.webpack;\n\n return {\n ...injectWywTurbopackRules(nextConfig, wywNext),\n webpack(config: Configuration, options: NextWebpackOptions) {\n const resolvedConfig =\n typeof userWebpack === 'function'\n ? userWebpack(config, options)\n : config;\n\n injectWywLoader(resolvedConfig, options, wywNext);\n\n return resolvedConfig;\n },\n };\n}\n"],"file":"index.mjs"}
|
package/package.json
CHANGED
|
@@ -1,33 +1,34 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wyw-in-js/nextjs",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0-alpha.1",
|
|
4
|
+
"type": "module",
|
|
4
5
|
"dependencies": {
|
|
5
|
-
"@wyw-in-js/
|
|
6
|
-
"@wyw-in-js/
|
|
6
|
+
"@wyw-in-js/shared": "2.0.0-alpha.1",
|
|
7
|
+
"@wyw-in-js/turbopack-loader": "2.0.0-alpha.1",
|
|
8
|
+
"@wyw-in-js/webpack-loader": "2.0.0-alpha.1"
|
|
7
9
|
},
|
|
8
10
|
"devDependencies": {
|
|
9
|
-
"@types/node": "^
|
|
10
|
-
"@wyw-in-js/babel-config": "workspace:*",
|
|
11
|
+
"@types/node": "^22.0.0",
|
|
11
12
|
"@wyw-in-js/eslint-config": "workspace:*",
|
|
12
13
|
"@wyw-in-js/ts-config": "workspace:*",
|
|
13
14
|
"next": ">=13.0.0",
|
|
14
15
|
"webpack": "^5.76.0"
|
|
15
16
|
},
|
|
16
17
|
"engines": {
|
|
17
|
-
"node": ">=
|
|
18
|
+
"node": ">=22.0.0"
|
|
18
19
|
},
|
|
19
20
|
"exports": {
|
|
20
|
-
"
|
|
21
|
-
|
|
22
|
-
|
|
21
|
+
".": {
|
|
22
|
+
"types": "./types/index.d.ts",
|
|
23
|
+
"default": "./esm/index.mjs"
|
|
24
|
+
}
|
|
23
25
|
},
|
|
24
26
|
"files": [
|
|
25
27
|
"esm/",
|
|
26
|
-
"lib/",
|
|
27
28
|
"types/"
|
|
28
29
|
],
|
|
29
30
|
"license": "MIT",
|
|
30
|
-
"main": "
|
|
31
|
+
"main": "esm/index.mjs",
|
|
31
32
|
"module": "esm/index.mjs",
|
|
32
33
|
"peerDependencies": {
|
|
33
34
|
"next": ">=13.0.0",
|
|
@@ -37,8 +38,7 @@
|
|
|
37
38
|
"access": "public"
|
|
38
39
|
},
|
|
39
40
|
"scripts": {
|
|
40
|
-
"build:esm": "
|
|
41
|
-
"build:lib": "cross-env NODE_ENV=legacy babel src --out-dir lib --extensions '.js,.jsx,.ts,.tsx' --source-maps --delete-dir-on-start",
|
|
41
|
+
"build:esm": "node ../../scripts/build-esm-oxc.mjs --out-file-extension .mjs",
|
|
42
42
|
"build:types": "tsc --project ./tsconfig.lib.json --baseUrl . --rootDir ./src",
|
|
43
43
|
"lint": "eslint --ext .js,.ts .",
|
|
44
44
|
"test": "bun test src"
|
package/types/index.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
+
import type { LoaderOptions as WywTurbopackLoaderOptions } from '@wyw-in-js/turbopack-loader';
|
|
1
2
|
import type { LoaderOptions as WywWebpackLoaderOptions } from '@wyw-in-js/webpack-loader';
|
|
2
3
|
import type { NextConfig } from 'next';
|
|
3
4
|
export type WywNextPluginOptions = {
|
|
4
5
|
loaderOptions?: Omit<WywWebpackLoaderOptions, 'extension' | 'sourceMap'> & Partial<Pick<WywWebpackLoaderOptions, 'extension' | 'sourceMap'>>;
|
|
5
|
-
turbopackLoaderOptions?:
|
|
6
|
+
turbopackLoaderOptions?: Partial<WywTurbopackLoaderOptions>;
|
|
6
7
|
};
|
|
7
8
|
export declare function withWyw(nextConfig?: NextConfig, wywNext?: WywNextPluginOptions): NextConfig;
|
package/types/index.js
CHANGED
|
@@ -1,11 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.withWyw = withWyw;
|
|
7
|
-
const fs_1 = __importDefault(require("fs"));
|
|
8
|
-
const path_1 = __importDefault(require("path"));
|
|
1
|
+
import { createRequire } from 'module';
|
|
2
|
+
import { mergeOxcResolverAlias, toNativeResolverAlias, } from '@wyw-in-js/shared';
|
|
9
3
|
const DEFAULT_EXTENSION = '.wyw-in-js.module.css';
|
|
10
4
|
const DEFAULT_TURBO_RULE_KEYS = ['*.js', '*.jsx', '*.ts', '*.tsx'];
|
|
11
5
|
const DEFAULT_REACT_IMPORT_OVERRIDES = {
|
|
@@ -13,13 +7,7 @@ const DEFAULT_REACT_IMPORT_OVERRIDES = {
|
|
|
13
7
|
'react/jsx-runtime': { mock: 'react/jsx-runtime' },
|
|
14
8
|
'react/jsx-dev-runtime': { mock: 'react/jsx-dev-runtime' },
|
|
15
9
|
};
|
|
16
|
-
const
|
|
17
|
-
const PLACEHOLDER_IGNORED_DIRS = new Set([
|
|
18
|
-
'.git',
|
|
19
|
-
'.next',
|
|
20
|
-
'.turbo',
|
|
21
|
-
'node_modules',
|
|
22
|
-
]);
|
|
10
|
+
const nodeRequire = createRequire(import.meta.url);
|
|
23
11
|
function isObject(value) {
|
|
24
12
|
return typeof value === 'object' && value !== null;
|
|
25
13
|
}
|
|
@@ -94,19 +82,29 @@ function isPlainObject(value) {
|
|
|
94
82
|
const proto = Object.getPrototypeOf(value);
|
|
95
83
|
return proto === Object.prototype || proto === null;
|
|
96
84
|
}
|
|
97
|
-
function
|
|
85
|
+
function assertJsonSerializable(value, name) {
|
|
98
86
|
const queue = [
|
|
99
87
|
{ path: name, value },
|
|
100
88
|
];
|
|
101
89
|
const seen = new Set();
|
|
102
90
|
while (queue.length) {
|
|
103
91
|
const current = queue.shift();
|
|
104
|
-
if (typeof current.value === 'function') {
|
|
105
|
-
throw new Error(`${current.path} must be JSON-serializable (functions are not supported in Turbopack loader options). Use "configFile" to pass non-JSON config.`);
|
|
106
|
-
}
|
|
107
92
|
if (current.value === null) {
|
|
108
93
|
// skip
|
|
109
94
|
}
|
|
95
|
+
else if (typeof current.value === 'undefined') {
|
|
96
|
+
// skip
|
|
97
|
+
}
|
|
98
|
+
else if (typeof current.value === 'string' ||
|
|
99
|
+
typeof current.value === 'number' ||
|
|
100
|
+
typeof current.value === 'boolean') {
|
|
101
|
+
// primitives are ok
|
|
102
|
+
}
|
|
103
|
+
else if (typeof current.value === 'function' ||
|
|
104
|
+
typeof current.value === 'symbol' ||
|
|
105
|
+
typeof current.value === 'bigint') {
|
|
106
|
+
throw new Error(`${current.path} must be JSON-serializable (functions, symbols and bigint are not supported in Turbopack loader options). Use "configFile" to pass non-JSON config.`);
|
|
107
|
+
}
|
|
110
108
|
else if (Array.isArray(current.value)) {
|
|
111
109
|
if (!seen.has(current.value)) {
|
|
112
110
|
seen.add(current.value);
|
|
@@ -119,6 +117,9 @@ function assertNoFunctions(value, name) {
|
|
|
119
117
|
Object.entries(current.value).forEach(([key, item]) => queue.push({ path: `${current.path}.${key}`, value: item }));
|
|
120
118
|
}
|
|
121
119
|
}
|
|
120
|
+
else {
|
|
121
|
+
throw new Error(`${current.path} must be JSON-serializable (only plain objects, arrays, and primitives are supported in Turbopack loader options). Use "configFile" to pass non-JSON config.`);
|
|
122
|
+
}
|
|
122
123
|
}
|
|
123
124
|
}
|
|
124
125
|
function createWywCssModuleRule(baseRule, extensionSuffix) {
|
|
@@ -193,14 +194,8 @@ function ensureWywCssModuleRules(config, extensionSuffix) {
|
|
|
193
194
|
});
|
|
194
195
|
}
|
|
195
196
|
function injectWywLoader(config, nextOptions, wywNext) {
|
|
196
|
-
const loader =
|
|
197
|
-
const nextBabelPreset = require.resolve('next/babel', {
|
|
198
|
-
paths: [process.cwd()],
|
|
199
|
-
});
|
|
197
|
+
const loader = nodeRequire.resolve('@wyw-in-js/webpack-loader');
|
|
200
198
|
const extension = wywNext.loaderOptions?.extension ?? DEFAULT_EXTENSION;
|
|
201
|
-
const babelOptions = wywNext.loaderOptions?.babelOptions ?? {
|
|
202
|
-
presets: [nextBabelPreset],
|
|
203
|
-
};
|
|
204
199
|
const userImportOverrides = wywNext.loaderOptions?.importOverrides;
|
|
205
200
|
const importOverrides = userImportOverrides
|
|
206
201
|
? { ...DEFAULT_REACT_IMPORT_OVERRIDES, ...userImportOverrides }
|
|
@@ -208,7 +203,6 @@ function injectWywLoader(config, nextOptions, wywNext) {
|
|
|
208
203
|
const loaderOptions = {
|
|
209
204
|
cssImport: 'import',
|
|
210
205
|
...wywNext.loaderOptions,
|
|
211
|
-
babelOptions,
|
|
212
206
|
extension,
|
|
213
207
|
importOverrides,
|
|
214
208
|
sourceMap: wywNext.loaderOptions?.sourceMap ?? nextOptions.dev,
|
|
@@ -234,58 +228,16 @@ function injectWywLoader(config, nextOptions, wywNext) {
|
|
|
234
228
|
});
|
|
235
229
|
ensureWywCssModuleRules(config, extension);
|
|
236
230
|
}
|
|
237
|
-
function ensureTurbopackCssPlaceholders(projectRoot) {
|
|
238
|
-
const queue = [projectRoot];
|
|
239
|
-
while (queue.length) {
|
|
240
|
-
const dir = queue.pop();
|
|
241
|
-
let entries;
|
|
242
|
-
try {
|
|
243
|
-
entries = fs_1.default.readdirSync(dir, { withFileTypes: true });
|
|
244
|
-
}
|
|
245
|
-
catch {
|
|
246
|
-
entries = [];
|
|
247
|
-
}
|
|
248
|
-
for (const entry of entries) {
|
|
249
|
-
if (entry.name !== '.' && entry.name !== '..') {
|
|
250
|
-
const entryPath = path_1.default.join(dir, entry.name);
|
|
251
|
-
if (entry.isDirectory()) {
|
|
252
|
-
if (!PLACEHOLDER_IGNORED_DIRS.has(entry.name)) {
|
|
253
|
-
queue.push(entryPath);
|
|
254
|
-
}
|
|
255
|
-
}
|
|
256
|
-
else if (entry.isFile()) {
|
|
257
|
-
const shouldIgnore = entry.name.startsWith('middleware.') ||
|
|
258
|
-
entry.name.endsWith('.d.ts');
|
|
259
|
-
if (!shouldIgnore) {
|
|
260
|
-
const ext = path_1.default.extname(entry.name);
|
|
261
|
-
if (PLACEHOLDER_EXTENSIONS.has(ext)) {
|
|
262
|
-
const baseName = path_1.default.basename(entry.name, ext);
|
|
263
|
-
const cssFilePath = path_1.default.join(path_1.default.dirname(entryPath), `${baseName}${DEFAULT_EXTENSION}`);
|
|
264
|
-
try {
|
|
265
|
-
fs_1.default.writeFileSync(cssFilePath, '', { flag: 'wx' });
|
|
266
|
-
}
|
|
267
|
-
catch (err) {
|
|
268
|
-
if (err.code !== 'EEXIST') {
|
|
269
|
-
throw err;
|
|
270
|
-
}
|
|
271
|
-
}
|
|
272
|
-
}
|
|
273
|
-
}
|
|
274
|
-
}
|
|
275
|
-
}
|
|
276
|
-
}
|
|
277
|
-
}
|
|
278
|
-
}
|
|
279
231
|
function shouldUseTurbopackConfig(nextConfig) {
|
|
280
232
|
const explicit = nextConfig.turbopack;
|
|
281
233
|
if (typeof explicit !== 'undefined') {
|
|
282
234
|
return true;
|
|
283
235
|
}
|
|
284
236
|
try {
|
|
285
|
-
const pkgPath =
|
|
237
|
+
const pkgPath = nodeRequire.resolve('next/package.json', {
|
|
286
238
|
paths: [process.cwd()],
|
|
287
239
|
});
|
|
288
|
-
const pkg =
|
|
240
|
+
const pkg = nodeRequire(pkgPath);
|
|
289
241
|
const version = typeof pkg.version === 'string' ? pkg.version : '';
|
|
290
242
|
const major = Number.parseInt(version.split('.')[0] ?? '', 10);
|
|
291
243
|
return Number.isFinite(major) && major >= 16;
|
|
@@ -295,32 +247,32 @@ function shouldUseTurbopackConfig(nextConfig) {
|
|
|
295
247
|
}
|
|
296
248
|
}
|
|
297
249
|
function injectWywTurbopackRules(nextConfig, wywNext) {
|
|
298
|
-
const loader =
|
|
299
|
-
const nextBabelPreset = require.resolve('next/babel', {
|
|
300
|
-
paths: [process.cwd()],
|
|
301
|
-
});
|
|
250
|
+
const loader = nodeRequire.resolve('@wyw-in-js/turbopack-loader');
|
|
302
251
|
const userOptions = wywNext.turbopackLoaderOptions ?? {};
|
|
303
|
-
|
|
252
|
+
assertJsonSerializable(userOptions, 'turbopackLoaderOptions');
|
|
253
|
+
const turbopackConfig = nextConfig
|
|
254
|
+
.turbopack;
|
|
255
|
+
const userTurbopack = isPlainObject(turbopackConfig) ? turbopackConfig : {};
|
|
256
|
+
const userExperimental = isPlainObject(nextConfig.experimental)
|
|
257
|
+
? nextConfig.experimental
|
|
258
|
+
: {};
|
|
259
|
+
const userTurbo = isPlainObject(userExperimental.turbo)
|
|
260
|
+
? userExperimental.turbo
|
|
261
|
+
: {};
|
|
262
|
+
const nativeResolverAlias = toNativeResolverAlias(userTurbopack.resolveAlias ?? userTurbo.resolveAlias);
|
|
263
|
+
const oxcOptions = mergeOxcResolverAlias(userOptions.oxcOptions, nativeResolverAlias);
|
|
304
264
|
const userImportOverrides = isPlainObject(userOptions.importOverrides)
|
|
305
265
|
? userOptions.importOverrides
|
|
306
266
|
: undefined;
|
|
307
267
|
const loaderOptions = {
|
|
308
|
-
babelOptions: { presets: [nextBabelPreset] },
|
|
309
268
|
sourceMap: process.env.NODE_ENV !== 'production',
|
|
310
269
|
...userOptions,
|
|
270
|
+
...(oxcOptions ? { oxcOptions } : {}),
|
|
311
271
|
importOverrides: userImportOverrides
|
|
312
272
|
? { ...DEFAULT_REACT_IMPORT_OVERRIDES, ...userImportOverrides }
|
|
313
273
|
: DEFAULT_REACT_IMPORT_OVERRIDES,
|
|
314
274
|
};
|
|
315
275
|
const useTurbopackConfig = shouldUseTurbopackConfig(nextConfig);
|
|
316
|
-
const isNextBuild = process.argv.includes('build');
|
|
317
|
-
const isWebpackBuild = process.argv.includes('--webpack');
|
|
318
|
-
if (useTurbopackConfig &&
|
|
319
|
-
process.env.NODE_ENV === 'production' &&
|
|
320
|
-
isNextBuild &&
|
|
321
|
-
!isWebpackBuild) {
|
|
322
|
-
ensureTurbopackCssPlaceholders(process.cwd());
|
|
323
|
-
}
|
|
324
276
|
const ruleValue = useTurbopackConfig
|
|
325
277
|
? {
|
|
326
278
|
loaders: [{ loader, options: loaderOptions }],
|
|
@@ -334,9 +286,6 @@ function injectWywTurbopackRules(nextConfig, wywNext) {
|
|
|
334
286
|
: [{ loader, options: loaderOptions }];
|
|
335
287
|
const wywRules = Object.fromEntries(DEFAULT_TURBO_RULE_KEYS.map((key) => [key, ruleValue]));
|
|
336
288
|
if (useTurbopackConfig) {
|
|
337
|
-
const turbopackConfig = nextConfig
|
|
338
|
-
.turbopack;
|
|
339
|
-
const userTurbopack = isPlainObject(turbopackConfig) ? turbopackConfig : {};
|
|
340
289
|
const userRules = isPlainObject(userTurbopack.rules)
|
|
341
290
|
? userTurbopack.rules
|
|
342
291
|
: {};
|
|
@@ -351,12 +300,6 @@ function injectWywTurbopackRules(nextConfig, wywNext) {
|
|
|
351
300
|
},
|
|
352
301
|
};
|
|
353
302
|
}
|
|
354
|
-
const userExperimental = isPlainObject(nextConfig.experimental)
|
|
355
|
-
? nextConfig.experimental
|
|
356
|
-
: {};
|
|
357
|
-
const userTurbo = isPlainObject(userExperimental.turbo)
|
|
358
|
-
? userExperimental.turbo
|
|
359
|
-
: {};
|
|
360
303
|
const userRules = isPlainObject(userTurbo.rules)
|
|
361
304
|
? userTurbo.rules
|
|
362
305
|
: {};
|
|
@@ -374,7 +317,7 @@ function injectWywTurbopackRules(nextConfig, wywNext) {
|
|
|
374
317
|
},
|
|
375
318
|
};
|
|
376
319
|
}
|
|
377
|
-
function withWyw(nextConfig = {}, wywNext = {}) {
|
|
320
|
+
export function withWyw(nextConfig = {}, wywNext = {}) {
|
|
378
321
|
const userWebpack = nextConfig.webpack;
|
|
379
322
|
return {
|
|
380
323
|
...injectWywTurbopackRules(nextConfig, wywNext),
|