Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async function collectPackages(context: RushContext, name: string, version: string,
pkgs: PackageMap): Promise {
let pkg = pkgs.getPackageInfo(name, version);
if (!pkg) {
const info = await context.getPackageInfo(name, version);
let files: string[];
if (info.isLocal) {
// For local packages, use `packlist` to get the list of files that npm would have packed
// into the tarball.
files = packlist.sync({ path: info.path });
}
else {
// For non-local packages, just copy everything.
files = await glob('**/*', {
nodir: true,
cwd: info.path
});
}
pkg = {
name: name,
version: version,
sourcePath: info.path,
files: files,
dependencies: []
};
it("should contain all files that your config referred.", () => {
const validFiles = new Set(
packlist.sync({ path: projectRoot })
.map(relPath => path.relative(projectRoot, path.resolve(projectRoot, relPath)))
);
const invalidFiles = getDependedFiles()
.map(filePath => path.relative(projectRoot, filePath))
.filter(filePath => !filePath.startsWith(`node_modules${path.sep}`) && !validFiles.has(filePath))
.sort();
assert.deepStrictEqual(
invalidFiles,
[],
`${invalidFiles.length} file(s) were not contained in your package. Check your 'package.json' and '.npmignore'.`
);
});
modulePaths.forEach(modulePath => {
const packageJson = pkgs[modulePath]
let moduleFilePaths
moduleFilePaths = packList.sync({ path: modulePath })
moduleFilePaths.forEach(moduleFilePath => {
if (includeModuleFile(packageJson, moduleFilePath)) {
filePaths.add(path.join(modulePath, moduleFilePath))
}
})
})
function checkPackage(packageDir: string, baselineDir: string, callback: (content: string, filename: string) => void) {
const list = packlist.sync({path: packageDir});
callback(list.join('\n'), path.join(baselineDir, 'packlist.txt'));
for (const file of list)
if (file.endsWith('.d.ts'))
callback(stripPrivateMembers(fs.readFileSync(path.join(packageDir, file), 'utf8')), path.join(baselineDir, file));
}
modulePaths.forEach(modulePath => {
const packageJson = pkgs[modulePath];
let moduleFilePaths;
moduleFilePaths = packList.sync({ path: modulePath });
moduleFilePaths.forEach(moduleFilePath => {
if (includeModuleFile(packageJson, moduleFilePath)) {
filePaths.add(path.join(modulePath, moduleFilePath));
}
});
});
modulePaths.forEach(modulePath => {
const packageJson = pkgs[modulePath];
let moduleFilePaths;
moduleFilePaths = packList.sync({ path: modulePath });
moduleFilePaths.forEach(moduleFilePath => {
if (includeModuleFile(packageJson, moduleFilePath)) {
filePaths.add(path.join(modulePath, moduleFilePath));
}
});
});
modulePaths.forEach(modulePath => {
const packageJson = pkgs[modulePath]
let moduleFilePaths
moduleFilePaths = packList.sync({ path: modulePath })
moduleFilePaths.forEach(moduleFilePath => {
if (includeModuleFile(packageJson, moduleFilePath)) {
filePaths.add(path.join(modulePath, moduleFilePath))
}
})
})