diff --git a/README.md b/README.md index 3df3d34c9..0b3e64047 100644 --- a/README.md +++ b/README.md @@ -540,6 +540,16 @@ Type: `boolean` Allow BrighterScript features (classes, interfaces, etc...) to be included in BrightScript (`.brs`) files, and force those files to be transpiled. +#### `bslibDestinationDir` + +Type: `string` + +Override the destination directory for the bslib.brs file. Use this if you want +to customize where the bslib.brs file is located in the staging directory. Note +that using a location outside of `source` will break scripts inside `source` +that depend on bslib.brs. Defaults to `source`. + + ## Ignore errors and warnings on a per-line basis In addition to disabling an entire class of errors in `bsconfig.json` by using `ignoreErrorCodes`, you may also disable errors for a subset of the complier rules within a file with the following comment flags: - `bs:disable-next-line` diff --git a/src/BsConfig.ts b/src/BsConfig.ts index 40fd49cc9..8dc633e7a 100644 --- a/src/BsConfig.ts +++ b/src/BsConfig.ts @@ -182,4 +182,12 @@ export interface BsConfig { * @default false */ allowBrighterScriptInBrightScript?: boolean; + + /** + * Override the destination directory for the bslib.brs file. Use this if + * you want to customize where the bslib.brs file is located in the staging + * directory. Note that using a location outside of `source` will break + * scripts inside `source` that depend on bslib.brs. Defaults to `source`. + */ + bslibDestinationDir?: string; } diff --git a/src/Program.spec.ts b/src/Program.spec.ts index 4f1c54848..7e559757e 100644 --- a/src/Program.spec.ts +++ b/src/Program.spec.ts @@ -1785,6 +1785,16 @@ describe('Program', () => { expect(fsExtra.pathExistsSync(s`${stagingDir}/source/bslib.brs`)).is.true; }); + it('copies the bslib.brs file to optionally specified directory', async () => { + fsExtra.ensureDirSync(program.options.stagingDir); + program.options.bslibDestinationDir = 'source/opt'; + program.validate(); + + await program.transpile([], program.options.stagingDir); + + expect(fsExtra.pathExistsSync(s`${stagingDir}/source/opt/bslib.brs`)).is.true; + }); + describe('getTranspiledFileContents', () => { it('fires plugin events', async () => { const file = program.setFile('source/main.brs', trim` @@ -2079,6 +2089,24 @@ describe('Program', () => { `); }); + it('uses custom bslib path when specified in .xml file', async () => { + program.options.bslibDestinationDir = 'source/opt'; + program.setFile('components/Component1.xml', trim` + + + + `); + await program.transpile([], program.options.stagingDir); + expect(trimMap( + fsExtra.readFileSync(s`${stagingDir}/components/Component1.xml`).toString() + )).to.eql(trim` + + +