Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
private parseThenStoreSource(filePath: string, raw: string): boolean {
filePath = upath.toUnix(filePath);
let sourcePath = filePath;
if (filePath.endsWith('.vue')) {
sourcePath = upath.addExt(filePath, '.ts');
raw = parseTypeScriptInVueFile(raw);
}
const version = this.calculateFileVersion(raw);
const previousSource = this.sources.get(sourcePath);
if (previousSource && previousSource.version === version) {
return false;
}
// console.log(sourcePath);
// https://github.com/Microsoft/TypeScript/blob/master/src/compiler/program.ts
this.sources.set(sourcePath, {
filePath: filePath,
source: TypeScript.createSourceFile(sourcePath, raw, this.target),
version: version
const packageJsonPath = upath.join(folder, 'package.json');
// console.log('Loading settings ' + chalk.cyan(json));
const x = await tryReadPackageJsonInstapackSettings(packageJsonPath);
// console.log(x);
const valid = validate(x);
if (valid === false) {
Shout.fatal('Abort Build: Invalid instapack project settings in ' + packageJsonPath);
console.error(validate.errors);
throw new Error('Invalid instapack project settings!');
}
Object.assign(settings, x);
settings.cssOut = upath.addExt(settings.cssOut, '.css');
settings.jsOut = upath.addExt(settings.jsOut, '.js');
// console.log(settings);
return settings;
}
}
}
}
if (realPath) {
// requested path was a html that needs analyzing for its own deps:
let htmlResources = resolveTemplateResources(realPath.source, localSrcPath, realPath.moduleName);
for (let htmlResource of htmlResources) {
processFromPath(resources, htmlResource.path, htmlResource, packagePath, localRelativeToDir, overrideBlock || extractBundleResourceData(htmlResource))
}
}
// if (path.changeExt(initialRealPath.source, 'js') !== initialRealPath.source && path.changeExt(initialRealPath.source, 'ts') !== initialRealPath.source) {
// .js:
let fromPathJs = path.addExt(fromPath, 'js');
realPath = getRealPathUniversal(fromPathJs, packagePath, relativeToDir);
if (realPath) {
debug(`<${path.basename(packagePath)}> ${realPath.path} => ${path.relative(packagePath, realPath.source)}`);
resources[fromPathJs] = Object.assign({}, resource, realPath, overrideBlock || {});
}
// .ts:
let fromPathTs = path.addExt(fromPath, 'ts');
realPath = getRealPathUniversal(fromPathTs, packagePath, relativeToDir);
if (realPath) {
debug(`<${path.basename(packagePath)}> ${realPath.path} => ${path.relative(packagePath, realPath.source)}`);
resources[fromPathTs] = Object.assign({}, resource, realPath, overrideBlock || {});
}
// .css:
let fromPathCss = path.addExt(fromPath, 'css');
realPath = getRealPathUniversal(fromPathCss, packagePath, relativeToDir);
if (realPath) {
port1: 0,
};
const ajv = new Ajv();
const settingsJsonSchema = yield fse.readJson(settingsJsonSchemaPath);
const validate = ajv.compile(settingsJsonSchema);
const packageJsonPath = upath.join(folder, 'package.json');
const x = yield tryReadPackageJsonInstapackSettings(packageJsonPath);
const valid = validate(x);
if (valid === false) {
Shout_1.Shout.fatal('Abort Build: Invalid instapack project settings in ' + packageJsonPath);
console.error(validate.errors);
throw new Error('Invalid instapack project settings!');
}
Object.assign(settings, x);
settings.cssOut = upath.addExt(settings.cssOut, '.css');
settings.jsOut = upath.addExt(settings.jsOut, '.js');
return settings;
});
}
get jsOutputFileName(): string {
return upath.addExt(this.variables.jsOut, '.js');
}
parseThenStoreSource(filePath, raw) {
filePath = upath.toUnix(filePath);
let sourcePath = filePath;
if (filePath.endsWith('.vue')) {
sourcePath = upath.addExt(filePath, '.ts');
raw = TypeScriptVueParser_1.parseTypeScriptInVueFile(raw);
}
const version = this.calculateFileVersion(raw);
const previousSource = this.sources.get(sourcePath);
if (previousSource && previousSource.version === version) {
return false;
}
this.sources.set(sourcePath, {
filePath: filePath,
source: TypeScript.createSourceFile(sourcePath, raw, this.target),
version: version
});
return true;
}
getSource(sourcePath) {
get cssOutputFileName(): string {
return upath.addExt(this.variables.cssOut, '.css');
}
get jsOutputFileName() {
return upath.addExt(this.variables.jsOut, '.js');
}
get jsChunkFileName() {
resources[fromPath] = (0, _assign2.default)({}, resource, realPath, overrideBlock || {});
var localSrcPath = realPath.modulePath || path.join(packagePath, relativeToDir);
var localRelativeToDir = relativeToDir;
if (realPath.modulePath) {
getResourcesOfPackage(resources, realPath.modulePath, undefined, overrideBlock || extractBundleResourceData(resource), realPath.moduleName);
if (moduleRootOverride[realPath.moduleName]) {
localRelativeToDir = moduleRootOverride[realPath.moduleName];
localSrcPath = path.join(realPath.modulePath, localRelativeToDir);
}
}
if (path.changeExt(realPath.source, 'html') !== realPath.source) {
var fromPathHtml = path.addExt(fromPath, 'html');
if (!resources[fromPathHtml]) {
realPath = getRealPathUniversal(fromPathHtml, packagePath, relativeToDir);
if (realPath) {
debug('<' + path.basename(packagePath) + '> ' + realPath.path + ' => ' + path.relative(packagePath, realPath.source));
resources[fromPathHtml] = (0, _assign2.default)({}, resource, realPath, overrideBlock || {});
}
}
}
if (realPath) {
var htmlResources = resolveTemplateResources(realPath.source, localSrcPath, realPath.moduleName);
for (var _iterator = htmlResources, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : (0, _getIterator3.default)(_iterator);;) {
var _ref;
if (_isArray) {
if (_i >= _iterator.length) break;