Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// Use esmodule loader if possible
if (b.type === 'js' && b.env.outputFormat === 'esmodule') {
if (!needsDynamicImportPolyfill) {
return `import('' + '${relativeBundlePath(bundle, b)}')`;
}
loader = IMPORT_POLYFILL;
} else if (b.type === 'js' && b.env.outputFormat === 'commonjs') {
return `Promise.resolve(require('' + '${relativeBundlePath(
bundle,
b
)}'))`;
}
let url = urlJoin(nullthrows(b.target.publicUrl), nullthrows(b.name));
return `require(${JSON.stringify(loader)})('${url}')`;
})
.filter(Boolean);
_getCachePath(cacheId: string, extension: string = '.v8'): FilePath {
return urlJoin(this.uri, cacheId.slice(0, 2), cacheId.slice(2) + extension);
}
} else {
for (let bundle of externalBundles) {
let filePath = nullthrows(bundle.getMainEntry()).filePath;
if (bundle.target == null) {
throw new Error('JSRuntime: Bundle did not have a target');
}
if (bundle.target.publicUrl == null) {
throw new Error(
'JSRuntime: Bundle target did not have a publicUrl'
);
}
assets.push({
filePath: filePath + '.js',
code: `module.exports = '${urlJoin(
bundle.target.publicUrl,
nullthrows(bundle.name)
)}'`,
dependency
});
}
}
}
return assets;
}
});
apply({bundle, bundleGraph, options}) {
if (bundle.env.context !== 'service-worker') {
return;
}
let code = `
import {createServiceWorker} from './service-worker';
createServiceWorker("${urlJoin(
bundle.target.publicUrl ?? '/',
'parcel-manifest.json'
)}");
`;
return [
{
filePath: __filename,
code,
isEntry: true
}
];
}
});
if (bundle.type === 'css') {
bundles.push({
tag: 'link',
attrs: {
rel: 'stylesheet',
href: urlJoin(
nullthrows(bundle.target).publicUrl ?? '/',
nullthrows(bundle.name),
),
},
});
} else if (bundle.type === 'js') {
bundles.push({
tag: 'script',
attrs: {
src: urlJoin(
nullthrows(bundle.target).publicUrl ?? '/',
nullthrows(bundle.name),
),
},
});
}
}
addBundlesToTree(bundles, tree);
}