Skip to content

Commit

Permalink
refactor: optimize "globalThis.__bundlerPathsOverrides" overrides
Browse files Browse the repository at this point in the history
  • Loading branch information
wd-David committed Aug 8, 2022
1 parent bed9af9 commit f52a79f
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 6 deletions.
5 changes: 1 addition & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,7 @@ export default function esbuildPluginPino({
.join(',')

const globalThisDeclaration = `
globalThis.__bundlerPathsOverrides =
globalThis.__bundlerPathsOverrides
? {...globalThis.__bundlerPathsOverrides, ${pinoOverrides}}
: {${pinoOverrides}};
globalThis.__bundlerPathsOverrides = { ...(globalThis.__bundlerPathsOverrides || {}), ${pinoOverrides}}
`

const code = functionDeclaration + globalThisDeclaration
Expand Down
4 changes: 2 additions & 2 deletions test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ describe('Test esbuildPluginPino', () => {
resolve(distFolder, firstFile as string),
'utf-8'
)
const overrides = `globalThis.__bundlerPathsOverrides = globalThis.__bundlerPathsOverrides ? { ...globalThis.__bundlerPathsOverrides, "thread-stream-worker": pinoBundlerAbsolutePath("./thread-stream-worker.js"), "pino-worker": pinoBundlerAbsolutePath("./pino-worker.js"), "pino-pipeline-worker": pinoBundlerAbsolutePath("./pino-pipeline-worker.js"), "pino/file": pinoBundlerAbsolutePath("./pino-file.js"), "pino-pretty": pinoBundlerAbsolutePath("./pino-pretty.js") } : { "thread-stream-worker": pinoBundlerAbsolutePath("./thread-stream-worker.js"), "pino-worker": pinoBundlerAbsolutePath("./pino-worker.js"), "pino-pipeline-worker": pinoBundlerAbsolutePath("./pino-pipeline-worker.js"), "pino/file": pinoBundlerAbsolutePath("./pino-file.js"), "pino-pretty": pinoBundlerAbsolutePath("./pino-pretty.js") };`
const overrides = `globalThis.__bundlerPathsOverrides = { ...globalThis.__bundlerPathsOverrides || {}, "thread-stream-worker": pinoBundlerAbsolutePath("./thread-stream-worker.js"), "pino-worker": pinoBundlerAbsolutePath("./pino-worker.js"), "pino-pipeline-worker": pinoBundlerAbsolutePath("./pino-pipeline-worker.js"), "pino/file": pinoBundlerAbsolutePath("./pino-file.js"), "pino-pretty": pinoBundlerAbsolutePath("./pino-pretty.js") };`
expect(firstContent.includes(functionDeclaration)).toBeTruthy()
expect(firstContent.includes(overrides)).toBeTruthy()

Expand Down Expand Up @@ -107,7 +107,7 @@ describe('Test esbuildPluginPino', () => {
resolve(distFolder, thirdFile as string),
'utf-8'
)
const overrides = `globalThis.__bundlerPathsOverrides = globalThis.__bundlerPathsOverrides ? { ...globalThis.__bundlerPathsOverrides, "thread-stream-worker": pinoBundlerAbsolutePath("./thread-stream-worker.js"), "pino-worker": pinoBundlerAbsolutePath("./pino-worker.js"), "pino-pipeline-worker": pinoBundlerAbsolutePath("./pino-pipeline-worker.js"), "pino/file": pinoBundlerAbsolutePath("./pino-file.js"), "pino-loki": pinoBundlerAbsolutePath("./pino-loki.js"), "pino-pretty": pinoBundlerAbsolutePath("./pino-pretty.js") } : { "thread-stream-worker": pinoBundlerAbsolutePath("./thread-stream-worker.js"), "pino-worker": pinoBundlerAbsolutePath("./pino-worker.js"), "pino-pipeline-worker": pinoBundlerAbsolutePath("./pino-pipeline-worker.js"), "pino/file": pinoBundlerAbsolutePath("./pino-file.js"), "pino-loki": pinoBundlerAbsolutePath("./pino-loki.js"), "pino-pretty": pinoBundlerAbsolutePath("./pino-pretty.js") };`
const overrides = `globalThis.__bundlerPathsOverrides = { ...globalThis.__bundlerPathsOverrides || {}, "thread-stream-worker": pinoBundlerAbsolutePath("./thread-stream-worker.js"), "pino-worker": pinoBundlerAbsolutePath("./pino-worker.js"), "pino-pipeline-worker": pinoBundlerAbsolutePath("./pino-pipeline-worker.js"), "pino/file": pinoBundlerAbsolutePath("./pino-file.js"), "pino-loki": pinoBundlerAbsolutePath("./pino-loki.js"), "pino-pretty": pinoBundlerAbsolutePath("./pino-pretty.js") };`
expect(thirdContent.includes(functionDeclaration)).toBeTruthy()
expect(thirdContent.includes(overrides)).toBeTruthy()

Expand Down

0 comments on commit f52a79f

Please sign in to comment.