Skip to content

Commit

Permalink
Prevent bsc plugins loading during ropm install (#35)
Browse files Browse the repository at this point in the history
Fixes #26
  • Loading branch information
TwitchBronBron authored Feb 20, 2021
1 parent 9b5c4be commit 90f3e7e
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 2 deletions.
52 changes: 50 additions & 2 deletions src/prefixer/ModuleManager.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import type { DepGraphNode } from '../TestHelpers.spec';
import { testProcess, file, fsEqual, createProjects, trim } from '../TestHelpers.spec';
import * as fsExtra from 'fs-extra';
import { InstallCommand } from '../commands/InstallCommand';

const hostDir = path.join(process.cwd(), '.tmp', 'hostApp');
const cwd = process.cwd();
const hostDir = path.join(cwd, '.tmp', 'hostApp');

describe('ModuleManager', () => {
let manager: ModuleManager;
Expand Down Expand Up @@ -1695,5 +1695,53 @@ describe('ModuleManager', () => {
]
});
});

it('prevents loading and running bsc plugins during ropm install', async () => {
manager.modules = createProjects(hostDir, hostDir, {
name: 'host',
dependencies: [{
name: 'logger',
_files: {
'source/loggerlib.brs': `
sub logInfo(message)
print message
end sub
`
}
}]
});

//create a bsc plugin for the lib
fsExtra.outputFileSync(`${hostDir}/node_modules/logger/plugin.js`, `
throw new Error('plugin loaded');
`);

fsExtra.outputFileSync(`${hostDir}/node_modules/logger/bsconfig.json`, JSON.stringify({
plugins: [
'./plugin.js'
]
}));

//create a bsc plugin for the host
fsExtra.outputFileSync(`${hostDir}/plugin.js`, `
throw new Error('plugin loaded');
`);

fsExtra.outputFileSync(`${hostDir}/bsconfig.json`, JSON.stringify({
plugins: [
'./plugin.js'
]
}));

try {
//change directory into hostDir to reproduce this issue
process.chdir(hostDir);
await managerProcess();
} finally {
//restore cwd regardless of the test
process.chdir(cwd);
}
//loading the plugin causes an exception, so if no errors are thrown, this test was successful
});
});
});
3 changes: 3 additions & 0 deletions src/prefixer/RopmModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,9 +212,12 @@ export class RopmModule {
util.mockProgramValidate();

await builder.run({
//specify an optional bogus bsconfig which prevents loading any bsconfig found in cwd
project: '?___not-real-bsconfig.json",',
copyToStaging: false,
createPackage: false,
rootDir: this.packageRootDir,
cwd: this.packageRootDir,
//hide all diagnostics, the package author should be responsible for ensuring their package is valid
diagnosticFilters: ['**/*'],
//hide log statements
Expand Down

0 comments on commit 90f3e7e

Please sign in to comment.