-
-
Notifications
You must be signed in to change notification settings - Fork 927
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix false positive CJS deprecation warning for dual-package plugins (#…
…7532) Co-authored-by: Masafumi Koba <473530+ybiquitous@users.noreply.github.com>
- Loading branch information
1 parent
d2c8d0d
commit fc88e99
Showing
19 changed files
with
199 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"stylelint": patch | ||
--- | ||
|
||
Fixed: false positive CJS deprecation warning for dual-package plugins |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
Empty file.
8 changes: 8 additions & 0 deletions
8
lib/utils/__tests__/fixtures/node_modules/@stylelint/dual-package/package.json
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import path from 'node:path'; | ||
|
||
import { fileURLToPath } from 'node:url'; | ||
|
||
import resolveSilent from '../resolveSilent.mjs'; | ||
|
||
const fixturesPath = fileURLToPath(new URL('./fixtures', import.meta.url)); | ||
|
||
it('should resolve ESM over commonjs for dual package', () => { | ||
expect(resolveSilent(fixturesPath, '@stylelint/dual-package')).toBe( | ||
path.resolve(fixturesPath, 'node_modules/@stylelint/dual-package/index.mjs'), | ||
); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
// NOTICE: This file is generated by Rollup. To modify it, | ||
// please instead edit the ESM counterpart and rebuild with Rollup (npm run build). | ||
'use strict'; | ||
|
||
const fs = require('node:fs'); | ||
const path = require('node:path'); | ||
const node_url = require('node:url'); | ||
const importMetaResolve = require('@dual-bundle/import-meta-resolve'); | ||
const resolveFrom = require('resolve-from'); | ||
|
||
/** | ||
* TODO: These suffixes are here for commonjs compatibility reason, we should remove these codes after migrating to pure ESM, because in ESM accurate paths are required | ||
*/ | ||
|
||
const pathSuffixes = ['', '.js', '.json', `${path.sep}index.js`, `${path.sep}index.json`]; | ||
|
||
const specifierSuffixes = ['', '.js', '.json', '/index.js', '/index.json']; | ||
|
||
/** | ||
* @param {string} parent | ||
* @param {string} lookup | ||
* @return {string | undefined} | ||
*/ | ||
function resolveSilent(parent, lookup) { | ||
if (path.isAbsolute(lookup)) { | ||
for (const suffix of pathSuffixes) { | ||
const filename = lookup + suffix; | ||
|
||
if (fs.existsSync(filename)) { | ||
return filename; | ||
} | ||
} | ||
|
||
return; | ||
} | ||
|
||
const base = node_url.pathToFileURL(path.resolve(parent, 'noop.js')).toString(); | ||
|
||
for (const suffix of specifierSuffixes) { | ||
try { | ||
const resolved = node_url.fileURLToPath(importMetaResolve.resolve(lookup + suffix, base)); | ||
|
||
if (fs.existsSync(resolved)) { | ||
return resolved; | ||
} | ||
} catch { | ||
// | ||
} | ||
} | ||
|
||
/** | ||
* Yarn P'n'P does not support pure ESM well by default, this is only a workaround for it | ||
* @see https://github.com/wooorm/import-meta-resolve/issues/23 | ||
* | ||
* TODO: this workaround is still necessary before native `import.meta.resolve` replacement | ||
*/ | ||
return resolveFrom.silent(parent, lookup); | ||
} | ||
|
||
module.exports = resolveSilent; |
Oops, something went wrong.