Switched from CommonJS exports to ESM exports

This commit is contained in:
Nathan Johnson 2022-04-17 09:26:01 -05:00
parent 052337aeaa
commit 09871cc01a
7 changed files with 23 additions and 19 deletions

BIN
ffmpeg-ffmpeg-0.10.2.tgz Normal file

Binary file not shown.

View File

@ -8,7 +8,15 @@ const webpackConfig = require('./webpack.config.dev');
const compiler = webpack(webpackConfig); const compiler = webpack(webpackConfig);
const app = express(); const app = express();
function coi(req, res, next) {
res.setHeader("Cross-Origin-Opener-Policy", "same-origin");
res.setHeader("Cross-Origin-Embedder-Policy", "require-corp");
next();
}
app.use(cors()); app.use(cors());
app.use(coi);
app.use('/', express.static(path.resolve(__dirname, '..'))); app.use('/', express.static(path.resolve(__dirname, '..')));
app.use(middleware(compiler, { publicPath: '/dist', writeToDisk: true })); app.use(middleware(compiler, { publicPath: '/dist', writeToDisk: true }));

View File

@ -3,8 +3,8 @@ const { devDependencies } = require('../../package.json');
/* /*
* Default options for browser environment * Default options for browser environment
*/ */
module.exports = { const corePath = typeof process !== 'undefined' && process.env.NODE_ENV === 'development'
corePath: typeof process !== 'undefined' && process.env.NODE_ENV === 'development'
? new URL('/node_modules/@ffmpeg/core/dist/ffmpeg-core.js', import.meta.url).href ? new URL('/node_modules/@ffmpeg/core/dist/ffmpeg-core.js', import.meta.url).href
: `https://unpkg.com/@ffmpeg/core@${devDependencies['@ffmpeg/core'].substring(1)}/dist/ffmpeg-core.js`, : `https://unpkg.com/@ffmpeg/core@${devDependencies['@ffmpeg/core'].substring(1)}/dist/ffmpeg-core.js`
};
export {corePath};

View File

@ -11,7 +11,7 @@ const readFromBlobOrFile = (blob) => (
}) })
); );
module.exports = async (_data) => { export const fetchFile = async (_data) => {
let data = _data; let data = _data;
if (typeof _data === 'undefined') { if (typeof _data === 'undefined') {
return new Uint8Array(); return new Uint8Array();

View File

@ -18,9 +18,9 @@ const toBlobURL = async (url, mimeType) => {
return blobURL; return blobURL;
}; };
if (typeof WorkerGlobalScope !== 'undefined' && self instanceof WorkerGlobalScope) { export const getCreateFFmpegCore = async ({ corePath: _corePath }) => {
// in Web Worker context // in Web Worker context
module.exports = async ({ corePath: _corePath }) => { if (typeof WorkerGlobalScope !== 'undefined' && self instanceof WorkerGlobalScope) {
if (typeof _corePath !== 'string') { if (typeof _corePath !== 'string') {
throw Error('corePath should be a string!'); throw Error('corePath should be a string!');
} }
@ -59,9 +59,7 @@ if (typeof WorkerGlobalScope !== 'undefined' && self instanceof WorkerGlobalScop
wasmPath, wasmPath,
workerPath, workerPath,
}); });
};
} else { } else {
module.exports = async ({ corePath: _corePath }) => {
if (typeof _corePath !== 'string') { if (typeof _corePath !== 'string') {
throw Error('corePath should be a string!'); throw Error('corePath should be a string!');
} }
@ -107,6 +105,8 @@ if (typeof WorkerGlobalScope !== 'undefined' && self instanceof WorkerGlobalScop
wasmPath, wasmPath,
workerPath, workerPath,
}); });
};
} }
}

View File

@ -1,9 +1,5 @@
const defaultOptions = require('./defaultOptions'); const defaultOptions = require('./defaultOptions');
const getCreateFFmpegCore = require('./getCreateFFmpegCore'); const {getCreateFFmpegCore} = require('./getCreateFFmpegCore');
const fetchFile = require('./fetchFile'); const {fetchFile} = require('./fetchFile');
module.exports = { export {defaultOptions, getCreateFFmpegCore, fetchFile};
defaultOptions,
getCreateFFmpegCore,
fetchFile,
};

View File

@ -2,7 +2,7 @@ require('regenerator-runtime/runtime');
const createFFmpeg = require('./createFFmpeg'); const createFFmpeg = require('./createFFmpeg');
const { fetchFile } = require('./node'); const { fetchFile } = require('./node');
module.exports = { export {
/* /*
* Create ffmpeg instance. * Create ffmpeg instance.
* Each ffmpeg instance owns an isolated MEMFS and works * Each ffmpeg instance owns an isolated MEMFS and works