Skip to content

Commit

Permalink
Merge pull request #2 from JennieJi/fix-release
Browse files Browse the repository at this point in the history
Fix release, replace dynamic loading parser, pack source
  • Loading branch information
JennieJi authored May 26, 2020
2 parents 15db264 + 9497a7f commit 4ea95da
Show file tree
Hide file tree
Showing 17 changed files with 2,415 additions and 98 deletions.
2 changes: 1 addition & 1 deletion .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
{
"type": "shell",
"label": "Build",
"command": "yarn run compile",
"command": "yarn run dev",
"problemMatcher": "$tsc-watch",
"isBackground": true,
"presentation": {
Expand Down
7 changes: 6 additions & 1 deletion .vscodeignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,14 @@
.vscode-test/**
out/test/**
src/**
.eslintrc
.gitignore
.prettierrc
**/tsconfig.json
**/.eslintrc.json
**/*.map
**/*.ts
**/*.log
**/*.log
node_modules/**
*.lock
webpack.config.js
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file. Dates are d

Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).

#### [v0.1.1](https://github.com/JennieJi/vscode-babel-ast-explorer/compare/vv0.1.0...vv0.1.1)

> 25 May 2020
#### v0.1.0

> 25 May 2020
Expand Down
17 changes: 12 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"name": "Jennie Ji",
"email": "[email protected]"
},
"version": "0.1.1",
"version": "0.1.3",
"license": "MIT",
"engines": {
"vscode": "^1.42.0"
Expand Down Expand Up @@ -74,9 +74,11 @@
"startingVersion": "v0.1.0"
},
"scripts": {
"vscode:prepublish": "yarn changelog && yarn run compile",
"vscode:prepublish": "yarn fetch:parser && yarn changelog && yarn run compile",
"changelog": "auto-changelog && git add CHANGELOG.md",
"compile": "tsc -p ./",
"fetch:parser": "node ./scripts/fetchParsers.js",
"compile": "webpack --mode production -p",
"dev": "webpack --mode development -p",
"lint": "eslint src --ext ts",
"watch": "tsc -watch -p ./",
"pretest": "yarn run compile && yarn run lint",
Expand All @@ -98,9 +100,15 @@
"eslint-plugin-prettier": "^3.1.3",
"glob": "^7.1.6",
"mocha": "^7.1.0",
"pacote": "^11.1.10",
"prettier": "^2.0.5",
"shebang-loader": "^0.0.1",
"ts-loader": "^7.0.5",
"ts-node": "^8.10.1",
"typescript": "^3.7.5",
"vscode-test": "^1.3.0"
"vscode-test": "^1.3.0",
"webpack": "^4.43.0",
"webpack-cli": "^3.3.11"
},
"repository": {
"type": "git",
Expand All @@ -110,7 +118,6 @@
"url": "https://github.com/JennieJi/vscode-babel-ast-explorer/issues"
},
"dependencies": {
"pacote": "^11.1.10",
"semver": "^7.3.2"
}
}
27 changes: 27 additions & 0 deletions scripts/fetchParsers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
const { packument, extract } = require('pacote');
const semver = require('semver');
const path = require('path');

const PACKAGE = '@babel/parser';

function parserPath(version = '') {
return path.resolve(__dirname, '../resources', PACKAGE, version);
}

async function getParserVersions() {
const data = await packument(PACKAGE);
return semver.rsort(Object.values(data.versions).map((d) => d.version));
}

function resolveVersion(version = 'latest') {
const spec = `${PACKAGE}@${version}`;
const dist = parserPath(version);
return extract(spec, dist).then((res) => {
console.log(`fetched ${spec} -> ${dist}`);
return res;
});
}

getParserVersions().then((versions) =>
Promise.all(versions.map(resolveVersion))
);
9 changes: 5 additions & 4 deletions src/MultiOptionsProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,14 @@ class MultiOptionsProvider implements vscode.TreeDataProvider<OptionNode> {
public getTreeItem({ label, value }: OptionNode): vscode.TreeItem {
const isEnabled = this.enabledOptions.includes(value);
const enabled = this.enabledOptions;
const iconPath = path.resolve(
__ASSET_PATH__,
isEnabled ? 'icons/green-tick.svg' : 'icons/grey-tick.svg'
);
return {
label,
id: value,
iconPath: path.resolve(
__dirname,
isEnabled ? 'icons/green-tick.svg' : 'icons/grey-tick.svg'
),
iconPath,
command: {
command: COMMANDS.update,
arguments: [
Expand Down
9 changes: 5 additions & 4 deletions src/SingleOptionProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,14 @@ class SingleOptionProvider implements vscode.TreeDataProvider<OptionNode> {

public getTreeItem({ label, value }: OptionNode): vscode.TreeItem {
const isEnabled = this.enabled === value;
const iconPath = path.resolve(
__ASSET_PATH__,
isEnabled ? 'icons/green-tick.svg' : 'icons/grey-tick.svg'
);
return {
label,
id: value,
iconPath: path.resolve(
__dirname,
isEnabled ? 'icons/green-tick.svg' : 'icons/grey-tick.svg'
),
iconPath,
command: {
command: COMMANDS.update,
arguments: [
Expand Down
7 changes: 6 additions & 1 deletion src/astView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,12 @@ class ASTView {
this.panel.title = this.getTitle();
this.panel.webview.html = 'Loading...';
this.codeVersion = this.getVersion();
this.panel.webview.html = await this.getWebviewContent();
const content = await this.getWebviewContent();
if (content) {
this.panel.webview.html = content;
} else {
this.panel.webview.html = 'Error: empty content';
}
}

private async getWebviewContent() {
Expand Down
29 changes: 14 additions & 15 deletions src/optionsView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,21 +39,20 @@ class OptionsView {
),
};

getParserVersions().then((versions) => {
this.viewers.version = this.registerView(
'babelAstExplorer-versions',
new SingleOptionProvider(
{
key: 'version',
items: versions.map((v) => ({
label: v,
value: v,
})),
},
versions[0]
)
);
});
const versions = getParserVersions();
this.viewers.version = this.registerView(
'babelAstExplorer-versions',
new SingleOptionProvider(
{
key: 'version',
items: versions.map((v) => ({
label: v,
value: v,
})),
},
versions[0]
)
);
}

registerView(
Expand Down
26 changes: 13 additions & 13 deletions src/parserVersion.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
import { packument, extract } from 'pacote';
import * as semver from 'semver';
import * as path from 'path';
import * as fs from 'fs';

const PACKAGE = '@babel/parser';

export async function getParserVersions() {
const data = await packument(PACKAGE);
return semver.rsort(Object.values(data.versions).map((d) => d.version));
function parserPath(version = '') {
return path.resolve(__ASSET_PATH__, PACKAGE, version);
}

export function parserPath(version: string) {
const spec = `${PACKAGE}@${version}`;
return path.resolve(__dirname, '../resources/', spec);
export function getParserVersions() {
return semver.rsort(fs.readdirSync(parserPath()));
}

export async function resolveVersion(version = 'latest') {
const spec = `${PACKAGE}@${version}`;
const dist = parserPath(version);
await extract(spec, dist);
const pkg = require(path.resolve(dist, 'package.json'));
return require(path.resolve(dist, pkg.main));
export async function resolveVersion(version?: string) {
if (!version) {
version = getParserVersions()[0];
}
const pkg = await import(
`${__ASSET_PATH__}/${PACKAGE}/${version}/package.json`
);
return await import(`${__ASSET_PATH__}/${PACKAGE}/${version}/${pkg.main}`);
}
2 changes: 1 addition & 1 deletion src/simpleTemplate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ function getTemplate(templatename: string) {
if (!templateCache[templatename]) {
const raw = fs
.readFileSync(
path.resolve(__dirname, '../resources/templates', templatename),
path.resolve(__ASSET_PATH__, 'templates', templatename),
'utf-8'
)
.toString();
Expand Down
1 change: 0 additions & 1 deletion src/test/suite/__snapshots__/getParserVersions.snap

This file was deleted.

19 changes: 0 additions & 19 deletions src/test/suite/parserVersion.test.ts

This file was deleted.

1 change: 1 addition & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
declare var __ASSET_PATH__: string;
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@
"outDir": "out",
"lib": ["es6"],
"sourceMap": true,
"rootDir": "src",
"rootDir": ".",
"strict": true /* enable all strict type-checking options */,
"resolveJsonModule": true
/* Additional Checks */
// "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */
// "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */
// "noUnusedParameters": true, /* Report errors on unused parameters. */
},
"include": ["src", "resources"],
"exclude": ["node_modules", ".vscode-test"]
}
65 changes: 65 additions & 0 deletions webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
'use strict';

const path = require('path');
const webpack = require('webpack');

const ASSET_PATH = path.resolve(__dirname, 'resources');

/**@type {import('webpack').Configuration}*/
const config = {
target: 'node', // vscode extensions run in a Node.js-context πŸ“– -> https://webpack.js.org/configuration/node/

entry: './src/extension.ts', // the entry point of this extension, πŸ“– -> https://webpack.js.org/configuration/entry-context/
output: {
// the bundle is stored in the 'dist' folder (check package.json), πŸ“– -> https://webpack.js.org/configuration/output/
path: path.resolve(__dirname, 'out'),
publicPath: path.resolve(__dirname, 'resources'),
filename: 'extension.js',
libraryTarget: 'commonjs2',
devtoolModuleFilenameTemplate: '../[resource-path]',
},
devtool: 'source-map',
externals: [
{
vscode: 'commonjs vscode', // the vscode-module is created on-the-fly and must be excluded. Add other modules that cannot be webpack'ed, πŸ“– -> https://webpack.js.org/configuration/externals/,
},
function (context, request, callback) {
if (/@babel\/parser/.test(request)) {
return callback(null, path.resolve(ASSET_PATH, request));
}
callback();
},
],
resolve: {
// support reading TypeScript and JavaScript files, πŸ“– -> https://github.com/TypeStrong/ts-loader
extensions: ['.ts', '.js', '.json'],
},
module: {
rules: [
{
test: /\.js$/,
include: /bin/,
use: [
{
loader: 'shebang-loader',
},
],
},
{
test: /\.ts$/,
exclude: /node_modules|\.vscode-test/,
use: [
{
loader: 'ts-loader',
},
],
},
],
},
plugins: [
new webpack.DefinePlugin({
__ASSET_PATH__: JSON.stringify(ASSET_PATH),
}),
],
};
module.exports = config;
Loading

0 comments on commit 4ea95da

Please sign in to comment.