Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build: update rollup lint rule from bad merge #20047

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
31 changes: 25 additions & 6 deletions tools/tslint/rollupConfigRule.ts
Expand Up @@ -34,6 +34,10 @@ const sourceFilePathBlacklist = [
// exceptions but we simply ignore those files from this rule.
/[/\\]packages[/\\]language-service[/\\]/,

// Compiler CLI is never part of a browser (there's a browser-rollup but it's managed
// separately.
/[/\\]packages[/\\]compiler-cli[/\\]/,

// service-worker is a special package that has more than one rollup config. It confuses
// this lint rule and we simply ignore those files.
/[/\\]packages[/\\]service-worker[/\\]/,
Expand Down Expand Up @@ -61,11 +65,26 @@ function _pathShouldBeLinted(path: string) {
}


/**
* .--. _________________
* {\ / q {\ / globalGlobalMap /
* { `\ \ (-(~` <__________________/
* { '.{`\ \ \ )
* {'-{ ' \ .-""'-. \ \
* {._{'.' \/ '.) \
* {_.{. {` |
* {._{ ' { ;'-=-. |
* {-.{.' { ';-=-.` /
* {._.{.; '-=- .'
* {_.-' `'.__ _,-'
* |||`
* .='==,
*/
interface RollupMatchInfo {
filePath: string;
globals: {[packageName: string]: string};
}
const rollupConfigMap = new Map<string, RollupMatchInfo>();
const globalGlobalRollupMap = new Map<string, RollupMatchInfo>();


export class Rule extends AbstractRule {
Expand All @@ -85,22 +104,22 @@ export class Rule extends AbstractRule {
let match: RollupMatchInfo;

while (p.startsWith(process.cwd())) {
if (rollupConfigMap.has(p)) {
if (globalGlobalRollupMap.has(p)) {
// We already resolved for this directory, just return it.
match = rollupConfigMap.get(p);
match = globalGlobalRollupMap.get(p);
break;
}

const allFiles = fs.readdirSync(p);
const maybeRollupPath = allFiles.find(x => _isRollupPath(path.join(p, x)));
if (maybeRollupPath) {
const rollupFilePath = path.join(p, maybeRollupPath);
const rollupConfig = require(rollupFilePath).default;
const rollupConfig = require(rollupFilePath);
match = {filePath: rollupFilePath, globals: rollupConfig && rollupConfig.globals};

// Update all paths that we checked along the way.
checkedPaths.forEach(path => rollupConfigMap.set(path, match));
rollupConfigMap.set(rollupFilePath, match);
checkedPaths.forEach(path => globalGlobalRollupMap.set(path, match));
globalGlobalRollupMap.set(rollupFilePath, match);
break;
}

Expand Down