-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(plugin): support for esm loader which its ext is .js
- Loading branch information
Showing
19 changed files
with
233 additions
and
709 deletions.
There are no files selected for viewing
18 changes: 18 additions & 0 deletions
18
e2e/cases/doctor-rspack/fixtures/loaders/esm/esm-serialize-query-to-comment.js
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,18 @@ | ||
import { parseQuery } from 'loader-utils'; | ||
|
||
/** | ||
* @type {import("webpack").LoaderDefinitionFunction<{}, {}>} | ||
*/ | ||
const loader = (input) => { | ||
const res = [input, `// ${JSON.stringify(this?.query || '')}`]; | ||
|
||
// Based on https://github.com/windicss/windicss-webpack-plugin/blob/main/src/loaders/windicss-template.ts#L42 | ||
// test the loader query | ||
if (this?.query && this?.query !== '') { | ||
res.push(`// ${JSON.stringify(parseQuery(this?.query))}`); | ||
} | ||
|
||
return res.join('\n'); | ||
}; | ||
|
||
export default loader; |
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 @@ | ||
{ | ||
"name": "@test/rsdoctor-rspack", | ||
"version": "0.1.0", | ||
"type": "module" | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,45 @@ | ||
import { dirname, join } from 'path'; | ||
import { SDK } from '@rsdoctor/types'; | ||
import { Package as PackageUtil } from '@rsdoctor/utils/common'; | ||
|
||
export function isPackagePath(path: string) { | ||
return /(^|[/\\])node_modules[/\\]/.test(path); | ||
} | ||
|
||
// TODO: add test for this function. | ||
export const readPackageJson = ( | ||
file: string, | ||
readFile?: SDK.GetPackageFile, | ||
): SDK.PackageBasicData | undefined => { | ||
let result: SDK.PackageJSONData | undefined; | ||
let current = file; | ||
|
||
while (current !== '/' && !result) { | ||
if (dirname(current) === current) { | ||
break; | ||
} | ||
current = dirname(current); | ||
if (readFile) { | ||
result = readFile(join(current, 'package.json')); | ||
} | ||
if (!readFile) { | ||
result = PackageUtil.getPackageMetaFromModulePath(file); | ||
} else if (!result?.name) { | ||
result = undefined; | ||
} | ||
} | ||
|
||
if (!result) { | ||
return; | ||
} | ||
|
||
// Some packages will put an empty package.json in the source folder. | ||
if (readFile && (!result.name || !result.version)) { | ||
return readPackageJson(dirname(current), readFile); | ||
} | ||
|
||
return { | ||
...result, | ||
root: current, | ||
}; | ||
}; |
Oops, something went wrong.