Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -228,5 +228,11 @@ module.exports = {
'@typescript-eslint/no-require-imports': 'off',
'@typescript-eslint/no-var-requires': 'off'
}
}, {
files: ['esbuild.js'],
rules: {
'@typescript-eslint/no-require-imports': 'off',
'@typescript-eslint/no-var-requires': 'off'
}
}]
};
23 changes: 19 additions & 4 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,27 @@
"presentation": {
"group": "watch",
"echo": true,
"reveal": "silent",
"reveal": "always",
"focus": false,
"panel": "shared"
},
"isBackground": true,
"problemMatcher": "$tsc-watch"
"problemMatcher": [
{
"pattern": {
"regexp": ""
},
"background": {
"activeOnStart": true,
"beginsPattern": {
"regexp": "\\[watch\\] build started"
},
"endsPattern": {
"regexp": "\\[watch\\] build finished"
}
}
}
]
},
{
"label": "watch-webviews",
Expand All @@ -41,7 +56,7 @@
"presentation": {
"group": "watch",
"echo": true,
"reveal": "silent",
"reveal": "always",
"focus": false,
"panel": "shared"
},
Expand Down Expand Up @@ -101,4 +116,4 @@
}
}
]
}
}
1 change: 1 addition & 0 deletions .vscodeignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ src/**
webviews/**
docs/**
.tmp/**
node_modules/**
**/*.map
**/*.spec.js
developer-guidelines.md
Expand Down
87 changes: 87 additions & 0 deletions esbuild.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
const esbuild = require('esbuild');
const fsExtra = require('fs-extra');
const path = require('path');
const bscVersion = require('./node_modules/brighterscript/package.json').version;

class Plugin {
constructor() {
this.name = 'empty-loader';
}
setup(build) {
build.onResolve({ filter: /^chokidar$/ }, args => ({
path: args.path,
namespace: 'empty-loader'
}));
build.onLoad({ filter: /.*/, namespace: 'empty-loader' }, () => ({
contents: '/*chokidar is not necessary for the language server so we replaced it with an empty object to fix esbuild issues*/\nmodule.exports = {}'
}));
}
}

//roku-test-automation's client/dist/utils.js uses `__dirname + '/../...'` to locate
//its JSON schema files and its on-device component bundle. When bundled into
//dist/extension.js, `__dirname` becomes the extension's `dist/` folder, so those
//paths are wrong. This plugin rewrites them to point at `dist/rta/...`; a post-build
//step copies the real files into that folder.
class RtaDirnamePlugin {
constructor() {
this.name = 'rta-dirname-rewrite';
}
setup(build) {
build.onLoad({ filter: /roku-test-automation[\\/]client[\\/]dist[\\/]utils\.js$/ }, (args) => {
let contents = fsExtra.readFileSync(args.path, 'utf8');
//order matters: replace longer/more-specific patterns before the generic '/../'
contents = contents
.replace(/__dirname \+ '\/\.\.\/\.\.\/device'/g, `__dirname + '/rta/device'`)
.replace(/__dirname \+ '\/\.\.\/rta-config\.schema\.json'/g, `__dirname + '/rta/rta-config.schema.json'`)
.replace(/__dirname \+ '\/\.\.\/'/g, `__dirname + '/rta/'`);
return { contents: contents, loader: 'js' };
});
}
}

esbuild.build({
entryPoints: {
'extension': './src/extension.ts',
'extension-web': './src/extension-web.ts',
'LanguageServerRunner': './src/LanguageServerRunner.ts',
'brighterscript': './node_modules/brighterscript/dist/index.js',
//brighterscript spawns a worker thread from `${__dirname}/run.js`; bundle that entry
//point to `dist/run.js` so the bundled brighterscript.js can locate it at runtime
'run': './node_modules/brighterscript/dist/lsp/worker/run.js'
},
bundle: true,
sourcemap: true,
splitting: false, //enable this once esbuild supports commonjs code splitting
treeShaking: true,
watch: process.argv.includes('--watch'),
minify: true, //process.argv.includes('--minify'),
mainFields: ['module', 'main'],
entryNames: '[name]',
outdir: 'dist',
external: [
'vscode'
],
define: {
// Inject the embedded brighterscript version at bundle time so
// LanguageServerManager can display it without require.resolve()
BSC_EMBEDDED_VERSION: JSON.stringify(bscVersion)
},
format: 'cjs',
platform: 'node',
logLevel: 'info',
plugins: [new Plugin(), new RtaDirnamePlugin()]
}).then(() => {
//copy roku-test-automation's runtime data files (JSON schemas + on-device component bundle)
//into dist/rta so the paths rewritten by RtaDirnamePlugin resolve correctly
const rtaSrc = path.join(__dirname, 'node_modules', 'roku-test-automation');
const rtaDst = path.join(__dirname, 'dist', 'rta');
fsExtra.ensureDirSync(rtaDst);
for (const file of ['requestArgs.schema.json', 'requestTypes.schema.json', 'rta-config.schema.json']) {
fsExtra.copySync(path.join(rtaSrc, 'client', file), path.join(rtaDst, file));
}
fsExtra.copySync(path.join(rtaSrc, 'device'), path.join(rtaDst, 'device'));
}).catch((e) => {
console.error(e);
process.exit(1);
});
Loading
Loading