Skip to content
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

fix(terser): __filename not defined #1367

Merged
merged 2 commits into from
Dec 21, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
tada5hi marked this conversation as resolved.
Show resolved Hide resolved
21 changes: 20 additions & 1 deletion packages/terser/src/module.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,31 @@
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') {
tada5hi marked this conversation as resolved.
Show resolved Hide resolved
// @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,
filePath,
maxWorkers: options.maxWorkers
});

Expand Down