chore(core): monorepo, esm targeting, improved management (#8707)

This commit is contained in:
Nathan Walker
2020-08-25 20:00:59 -07:00
committed by GitHub
parent 6f15334934
commit 020ad4da37
4271 changed files with 148599 additions and 149734 deletions

View File

@ -0,0 +1,35 @@
const parseFile = require("path").parse;
function PlatformSuffixPlugin(platform) {
this.platform = platform;
}
exports.PlatformSuffixPlugin = PlatformSuffixPlugin;
PlatformSuffixPlugin.prototype.apply = function(resolver) {
var platform = this.platform;
resolver.plugin("file", function(request, callback) {
const fs = this.fileSystem;
const file = this.join(request.path, request.request);
const query = request.query;
const pFile = parseFile(file);
const platformFile = this.join(pFile.dir, pFile.name + ("." + platform) + pFile.ext);
fs.stat(platformFile, (err, stat) => {
if (!err && stat && stat.isFile()) {
const err = undefined;
const path = platformFile;
callback(err, { file: true, path, query });
} else {
fs.stat(file, (err, stat) => {
if (!err && stat && stat.isFile()) {
const err = undefined;
const path = file;
callback(err, { file: true, path, query });
} else {
callback();
}
});
}
});
});
}