Skip to content

Commit

Permalink
fix(terser): __filename not defined
Browse files Browse the repository at this point in the history
  • Loading branch information
tada5hi committed Dec 6, 2022
1 parent fb11bd3 commit bd94161
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
1 change: 1 addition & 0 deletions CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
/packages/babel/ @Andarist
/packages/image/ @tjenkinson
/packages/node-resolve/ @tjenkinson
/packages/terser/ @tada5hi
19 changes: 19 additions & 0 deletions packages/terser/src/module.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,29 @@
import { fileURLToPath } from 'url';

import type { NormalizedOutputOptions, RenderedChunk } from 'rollup';
import { hasOwnProperty, isObject, merge } from 'smob';

import type { Options } from './type';
import { WorkerPool } from './worker-pool';

export default function terser(options: Options = {}) {
let filePath: string | undefined;

if (typeof __filename !== 'undefined') {
filePath = __filename;
} else {
// @ts-ignore
// eslint-disable-next-line no-lonely-if
if (typeof import.meta !== 'undefined') {
// @ts-ignore
filePath = fileURLToPath(import.meta.url);
}
}

if (typeof filePath === 'undefined') {
throw new Error('File path could not be determined.');
}

const workerPool = new WorkerPool({
filePath: __filename,
maxWorkers: options.maxWorkers
Expand Down

0 comments on commit bd94161

Please sign in to comment.