File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -12,6 +12,9 @@ and this project adheres to
1212
1313### Changed
1414
15+ - Exclude Deno and DOMException from distribution shim.
16+ - Refine retrieval of Node/Deno version.
17+
1518### Fixed
1619
1720### Removed
Original file line number Diff line number Diff line change @@ -8,8 +8,15 @@ await build({
88 rootTestDir : "./tests" ,
99 outDir : "./npm" ,
1010 shims : {
11- deno : true , // Required for `Deno.test`, `Deno.env`, etc.
12- domException : true , // https://deno.land/std/async/delay.ts relies on DOMException
11+ // Tests require `Deno.test` and `Deno.env`.
12+ // Although `Deno.version` is used, it doesn't need to be shimmed since
13+ // it won't be used when the user runs the module in Node.
14+ deno : "dev" ,
15+
16+ // https://deno.land/std/async/delay.ts relies on DOMException.
17+ // This is only used in tests.
18+ domException : "dev" , // Only used in tests.
19+
1320 undici : true , // Required for `fetch`
1421 } ,
1522 package : {
Original file line number Diff line number Diff line change @@ -77,15 +77,23 @@ function getSource() {
7777 const moduleSource = `serpapi@${ version } ` ;
7878 try {
7979 // Check if running in Node.js
80+ // dnt-shim-ignore
8081 // deno-lint-ignore no-explicit-any
81- if ( ( globalThis as any ) ?. process ?. version ) {
82- // deno-lint-ignore no-explicit-any
83- const nodeVersion = ( globalThis as any ) . process . version . replace ( "v" , "" ) ;
82+ const nodeVersion = ( globalThis as any ) . process ?. versions ?. node ;
83+ if ( nodeVersion ) {
8484 return `nodejs@${ nodeVersion } ,${ moduleSource } ` ;
8585 }
8686
87- // Assumes running in Deno instead
88- return `deno@${ Deno . version . deno } ,${ moduleSource } ` ;
87+ // Assumes running in Deno instead. https://deno.land/api?s=Deno.version
88+ // Deno.version is not shimmed since it's not used when ran in a Node env.
89+ // dnt-shim-ignore
90+ // deno-lint-ignore no-explicit-any
91+ const denoVersion = ( globalThis as any ) . Deno ?. version ?. deno ;
92+ if ( denoVersion ) {
93+ return `deno@${ denoVersion } ,${ moduleSource } ` ;
94+ }
95+
96+ return `nodejs,${ moduleSource } ` ;
8997 } catch {
9098 // If something unexpectedly occurs, revert to "nodejs".
9199 return `nodejs,${ moduleSource } ` ;
You can’t perform that action at this time.
0 commit comments