next-transpile-modules
Advanced tools
Comparing version 7.0.0 to 7.1.0
{ | ||
"name": "next-transpile-modules", | ||
"version": "7.0.0", | ||
"version": "7.1.0", | ||
"license": "MIT", | ||
@@ -27,6 +27,6 @@ "author": "Pierre de la Martinière <pierre.de.la.martiniere@gmail.com>", | ||
"test:prepare:yarn-workspaces-symlinks": "yarn --cwd src/__tests__/__apps__/yarn-workspaces-symlinks/app run build", | ||
"test:prepare:webpack-5": "yarn --cwd src/__tests__/__apps__/webpack-4/app run build", | ||
"test:prepare:webpack-5-symlinks": "yarn --cwd src/__tests__/__apps__/webpack-4-symlinks/app run build", | ||
"test:prepare:webpack-4": "yarn --cwd src/__tests__/__apps__/webpack-4/app run build", | ||
"test:prepare:webpack-4-symlinks": "yarn --cwd src/__tests__/__apps__/webpack-4-symlinks/app run build", | ||
"test:prepare:pnpm": "npm run build --prefix=src/__tests__/__apps__/pnpm", | ||
"test:prepare": "npm run test:prepare:npm-basic && npm run test:prepare:yarn-workspaces && npm run test:prepare:yarn-workspaces-symlinks && npm run test:prepare:webpack-5 && npm run test:prepare:webpack-5-symlinks && npm run test:prepare:pnpm" | ||
"test:prepare": "npm run test:prepare:npm-basic && npm run test:prepare:yarn-workspaces && npm run test:prepare:yarn-workspaces-symlinks && npm run test:prepare:webpack-4 && npm run test:prepare:webpack-4-symlinks && npm run test:prepare:pnpm" | ||
}, | ||
@@ -33,0 +33,0 @@ "repository": { |
@@ -102,3 +102,3 @@ # Next.js + Transpile `node_modules` | ||
- please declare `withTM` as your last plugin (the "most nested" one). | ||
- make sure all your packages have [a valid `main` field](https://docs.npmjs.com/cli/v6/configuring-npm/package-json#main). | ||
- ~~make sure all your packages have [a valid `main` field](https://docs.npmjs.com/cli/v6/configuring-npm/package-json#main).~~ (not needed anymore since `7.1.0`) | ||
- there is currently no way to transpile only parts of a package, it's all or nothing | ||
@@ -105,0 +105,0 @@ |
@@ -114,32 +114,39 @@ /** | ||
const getPackageRootDirectory = (module) => { | ||
let packageDirectory; | ||
let packageLookupDirectory; | ||
let packageRootDirectory; | ||
try { | ||
// Get the module path | ||
packageDirectory = resolve(CWD, module); | ||
if (!packageDirectory) { | ||
throw new Error( | ||
`next-transpile-modules - could not resolve module "${module}". Are you sure the name module you are trying to transpile is correct, and it has a "main" or an "exports" field? ` | ||
packageLookupDirectory = resolve(CWD, path.join(module, 'package.json')); | ||
packageRootDirectory = path.dirname(packageLookupDirectory); | ||
} catch (err) { | ||
// DEPRECATED: previous lookup for specific modules, it's confusing, and | ||
// will be removed in a next major version | ||
try { | ||
logger( | ||
`DEPRECATED - fallbacking to previous module resolution system for module "${module}", you can now just pass the name of the package to transpile and it will detect its real path without you having to pass a sub-module.`, | ||
true | ||
); | ||
} | ||
// Get the location of its package.json | ||
const pkgPath = escalade(packageDirectory, (dir, names) => { | ||
if (names.includes('package.json')) { | ||
return 'package.json'; | ||
// Get the module path | ||
packageLookupDirectory = resolve(CWD, module); | ||
// Get the location of its package.json | ||
const packageJsonPath = escalade(packageLookupDirectory, (_dir, names) => { | ||
if (names.includes('package.json')) { | ||
return 'package.json'; | ||
} | ||
return false; | ||
}); | ||
if (packageJsonPath == null) { | ||
throw new Error( | ||
`next-transpile-modules - an error happened when trying to get the root directory of "${module}". Is it missing a package.json?\n${err}` | ||
); | ||
} | ||
return false; | ||
}); | ||
if (pkgPath == null) { | ||
packageRootDirectory = path.dirname(packageJsonPath); | ||
} catch (err) { | ||
throw new Error( | ||
`next-transpile-modules - an error happened when trying to get the root directory of "${module}". Is it missing a package.json?\n${err}` | ||
`next-transpile-modules - an unexpected error happened when trying to resolve "${module}". Are you sure the name module you are trying to transpile is correct, and it has a "main" or an "exports" field?\n${err}` | ||
); | ||
} | ||
packageRootDirectory = path.dirname(pkgPath); | ||
} catch (err) { | ||
throw new Error( | ||
`next-transpile-modules - an unexpected error happened when trying to resolve "${module}"\n${err}` | ||
); | ||
} | ||
@@ -150,2 +157,4 @@ | ||
logger(`trying to resolve the following modules:\n${modules.map((mod) => ` - ${mod}`).join('\n')}`); | ||
// Resolve modules to their real paths | ||
@@ -265,2 +274,26 @@ const modulesPaths = modules.map(getPackageRootDirectory); | ||
const nextGlobalCssErrorLoader = nextCssLoaders.oneOf.find( | ||
(rule) => | ||
rule && | ||
rule.use && | ||
rule.use.options && | ||
rule.use.options.reason && | ||
rule.use.options.reason.startsWith( | ||
'Global CSS \x1B[1mcannot\x1B[22m be imported from within \x1B[1mnode_modules\x1B[22m.' | ||
) | ||
); | ||
const nextGlobalCssAppErrorLoader = nextCssLoaders.oneOf.find( | ||
(rule) => | ||
rule && | ||
rule.use && | ||
rule.use.options && | ||
rule.use.options.reason && | ||
rule.use.options.reason.startsWith( | ||
'Global CSS \x1B[1mcannot\x1B[22m be imported from files other than your \x1B[1mCustom <App>\x1B[22m. Please move all global CSS imports to \x1B[36mpages/_app.jsx\x1B[39m. Or convert the import to Component-Level CSS (CSS Modules).' | ||
) | ||
); | ||
const nextGlobalCssLoader = nextCssLoaders.oneOf.find((rule) => regexEqual(rule.test, /(?<!\.module)\.css$/)); | ||
if (nextCssLoader) { | ||
@@ -281,2 +314,20 @@ nextCssLoader.issuer.or = nextCssLoader.issuer.and ? nextCssLoader.issuer.and.concat(matcher) : matcher; | ||
} | ||
// Disable "css cannot be imported from node_modules" | ||
// TODO: issuer optimization | ||
if (nextGlobalCssErrorLoader) { | ||
nextGlobalCssErrorLoader.issuer.and = nextGlobalCssErrorLoader.issuer.and.concat(() => false); | ||
} | ||
// Disable "css can only be imported from App" | ||
// TODO: issuer optimization | ||
if (nextGlobalCssAppErrorLoader) { | ||
nextGlobalCssAppErrorLoader.issuer = {}; | ||
nextGlobalCssAppErrorLoader.issuer.and = [() => false]; | ||
} | ||
// Enable global CSS loader for node_modules | ||
if (nextGlobalCssLoader) { | ||
delete nextGlobalCssLoader.issuer.not; | ||
} | ||
} | ||
@@ -283,0 +334,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
29036
314