-
Notifications
You must be signed in to change notification settings - Fork 43
feat: output uses "type": "module" when esModule is set to true
#478
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,7 +8,8 @@ | |
| "rules": { | ||
| "exclude": [ | ||
| "no-explicit-any", | ||
| "camelcase" | ||
| "camelcase", | ||
| "no-import-prefix" | ||
| ] | ||
| } | ||
| }, | ||
|
|
||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -35,6 +35,14 @@ export function getPackageJson({ | |
| path: e.replace(/\.tsx?$/i, ".js"), | ||
| types: e.replace(/\.tsx?$/i, ".d.ts"), | ||
| })); | ||
| // include "type" field if we are including esm | ||
| const type = { | ||
| ...(includeEsModule | ||
| ? { | ||
| type: "module", | ||
| } | ||
| : {}), | ||
| }; | ||
|
Comment on lines
+39
to
+45
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Includes |
||
| const exports = finalEntryPoints.filter((e) => e.kind === "export"); | ||
| const binaries = finalEntryPoints.filter((e) => e.kind === "bin"); | ||
| const dependencies = { | ||
|
|
@@ -111,6 +119,7 @@ export function getPackageJson({ | |
| const final: Record<string, unknown> = { | ||
| ...mainExport, | ||
| ...binaryExport, | ||
| ...type, | ||
| ...packageJsonObj, | ||
| scripts: {}, | ||
| ...deleteEmptyKeys({ | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,6 +11,16 @@ export function getTestRunnerCode(options: { | |
| }) { | ||
| const usesDenoTest = options.denoTestShimPackageName != null; | ||
| const writer = createWriter(); | ||
|
|
||
| if (options.includeEsModule) { | ||
| // ensure compatibility with esm ("type": "module") | ||
| writer.writeLine(`import { createRequire } from 'module';`); | ||
| writer.writeLine(`const require = createRequire(import.meta.url);`); | ||
| writer.writeLine( | ||
| `const __dirname = new URL(".", import.meta.url).pathname;`, | ||
| ); | ||
| } | ||
|
Comment on lines
+15
to
+22
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I considered polyfilling the safer way to enable ESM compatibility instead of outputting ES modules directly. |
||
|
|
||
| writer.writeLine(`const pc = require("picocolors");`) | ||
| .writeLine(`const process = require("process");`); | ||
| if (usesDenoTest) { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
| // Copyright 2018-2024 the Deno authors. MIT license. | ||
|
|
||
| import { parse } from "jsr:@std/csv/parse"; | ||
| import { parse } from "jsr:@std/csv@1.0.6/parse"; | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I added a version specifier to fix a linter error. The version used is based on the latest |
||
| import { assertEquals } from "jsr:@std/[email protected]/assert-equals"; | ||
| import * as fs from "node:fs"; | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've run into linter issues with the existing code using inline imports. This rule got added to the default ruleset in Deno 2.5.
My assumption is the project's okay with inline imports, so I decided to exclude the rule instead. Let me know if I should rather refactor inline imports instead.