Skip to content

Commit

Permalink
build(config): use import.meta.dirname and import.meta.filename
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisguttandin committed Apr 10, 2024
1 parent da08d6d commit 31fe5f5
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions config/rollup/bundle.mjs
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import { join, resolve as resolvePath } from 'path';
import { readFile, readFileSync, readlink, stat } from 'fs';
import babel from '@rollup/plugin-babel';
import { fileURLToPath } from 'url';
import { fs } from 'memfs';
import { join } from 'path';
import replace from '@rollup/plugin-replace';
import webpack from 'webpack';
// eslint-disable-next-line node/file-extensions-in-import
import webpackConfig from '../webpack/worker-es5.mjs';

const workerFile = readFileSync('src/worker/worker.ts', 'utf8');
Expand All @@ -15,6 +13,7 @@ if (result === null) {
throw new Error('The worker file could not be parsed.');
}

const virtualPath = resolvePath(import.meta.dirname, '../../src/worker.js');
const workerString = result.groups.workerString;

// eslint-disable-next-line import/no-default-export
Expand All @@ -23,7 +22,7 @@ export default new Promise((resolve, reject) => {

compiler.inputFileSystem = {
readFile(path, ...args) {
if (path === fileURLToPath(new URL('../../src/worker.js', import.meta.url))) {
if (path === virtualPath) {
args.pop()(null, "import 'midi-json-parser-worker';");

return;
Expand All @@ -32,14 +31,14 @@ export default new Promise((resolve, reject) => {
return readFile(path, ...args);
},
readlink(path, callback) {
if (path === fileURLToPath(new URL('../../src/worker.js', import.meta.url))) {
return readlink(fileURLToPath(new URL(import.meta.url)), callback);
if (path === virtualPath) {
return readlink(import.meta.filename, callback);
}

return readlink(path, callback);
},
stat(path, ...args) {
if (path === fileURLToPath(new URL('../../src/worker.js', import.meta.url))) {
if (path === virtualPath) {
args.pop()(null, {
isFile() {
return true;
Expand Down

0 comments on commit 31fe5f5

Please sign in to comment.