Skip to content

Commit

Permalink
Merge branch 'main' of github.com:nicoespeon/abracadabra
Browse files Browse the repository at this point in the history
  • Loading branch information
长风 committed Jan 8, 2022
2 parents ed6b6bd + 10d590e commit 1243a10
Show file tree
Hide file tree
Showing 11 changed files with 806 additions and 351 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
out
node_modules
.vscode-test/
.vscode-test-web/
*.vsix

# Created by https://www.gitignore.io/api/node,visualstudiocode
Expand Down
2 changes: 1 addition & 1 deletion .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
// See http://go.microsoft.com/fwlink/?LinkId=827846
// for the documentation about the extensions.json format
"recommendations": []
"recommendations": ["nicoespeon.abracadabra"]
}
15 changes: 14 additions & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,20 @@
"${workspaceFolder}/src/playground"
],
"outFiles": ["${workspaceFolder}/out/**/*.js"],
"preLaunchTask": "npm: build"
"preLaunchTask": "npm: build:node"
},
{
"name": "Run Web Extension in VS Code",
"type": "pwa-extensionHost",
"debugWebWorkerHost": true,
"request": "launch",
"args": [
"--extensionDevelopmentPath=${workspaceFolder}",
"--extensionDevelopmentKind=web",
"${workspaceFolder}/src/playground"
],
"outFiles": ["${workspaceFolder}/out/**/*.js"],
"preLaunchTask": "npm: build:browser"
}
]
}
5 changes: 4 additions & 1 deletion .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
"tasks": [
{
"type": "npm",
"script": "build"
"script": "build",
"group": "build",
"isBackground": true,
"problemMatcher": ["$ts-webpack-watch"]
}
]
}
10 changes: 9 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,17 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [6.9.0] - 2022-01-07 - He's a Tramp 🐶

### Fixed

- @j4k0xb fixed the action provider for the "Convert For to Foreach" refactoring. Great catch!

### Added

- Inline Variable inside a template literal will remove the extraneous `${}` so you don't end up with `${"some string"}` in the middle of your template string.
- Extract Variable now works in for..of statements.
- Abracadabra is now available on VS Code web! That means you can install (and use) the extension when working on https://vscode.dev or https://github.dev for instance.

## [6.8.0] - 2021-11-25 - Extract De Vil 🐶

Expand Down Expand Up @@ -1522,7 +1529,8 @@ function doSomething(someData) {

</details>

[unreleased]: https://github.com/nicoespeon/abracadabra/compare/6.8.0...HEAD
[unreleased]: https://github.com/nicoespeon/abracadabra/compare/6.9.0...HEAD
[6.9.0]: https://github.com/nicoespeon/abracadabra/compare/6.8.0...6.9.0
[6.8.0]: https://github.com/nicoespeon/abracadabra/compare/6.7.1...6.8.0
[6.7.1]: https://github.com/nicoespeon/abracadabra/compare/6.7.0...6.7.1
[6.7.0]: https://github.com/nicoespeon/abracadabra/compare/6.6.0...6.7.0
Expand Down
66 changes: 38 additions & 28 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "abracadabra",
"version": "6.8.0",
"version": "6.9.0",
"displayName": "Abracadabra, refactor this!",
"publisher": "nicoespeon",
"description": "Automated refactorings for VS Code, in JavaScript and TypeScript.",
Expand Down Expand Up @@ -31,10 +31,11 @@
"theme": "dark"
},
"engines": {
"vscode": "^1.62.0",
"vscode": "^1.63.1",
"node": ">=14.0.0"
},
"main": "./out/extension.js",
"browser": "./out/extension-browser.js",
"scripts": {
"contrib": "all-contributors",
"prepare": "husky install",
Expand All @@ -44,12 +45,13 @@
"pretest:contract": "tsc -p ./",
"test:contract": "node ./out/test/run-contract-tests.js",
"test:ci": "yarn test && yarn test:contract",
"build": "webpack --mode none",
"watch": "webpack --mode none --watch",
"typecheck": "tsc -p tsconfig.json --noEmit",
"lint": "eslint -c .eslintrc.js --ext .ts src",
"build": "run-p -l build:*",
"build:node": "webpack",
"build:browser": "webpack --env browser",
"prepackage": "rm -rf dist/*.vsix && rm -rf out/",
"vscode:prepublish": "webpack --mode production",
"vscode:prepublish": "run-p -l \"build:* --mode production\"",
"package": "vsce package",
"postpackage": "mkdir -p dist && mv *.vsix dist",
"package:install": "code --install-extension dist/*.vsix",
Expand All @@ -59,52 +61,60 @@
},
"devDependencies": {
"@types/babel__traverse": "7.14.2",
"@types/chai": "4.2.22",
"@types/jest": "27.0.3",
"@types/chai": "4.3.0",
"@types/jest": "27.4.0",
"@types/jscodeshift": "0.11.2",
"@types/mocha": "9.0.0",
"@types/node": "16.11.11",
"@types/node": "17.0.6",
"@types/path-browserify": "1.0.0",
"@types/pluralize": "0.0.29",
"@types/sinon": "10.0.4",
"@types/vscode": "1.62.0",
"@typescript-eslint/eslint-plugin": "^5.7.0",
"@typescript-eslint/parser": "^5.7.0",
"@vscode/test-electron": "1.6.2",
"@types/sinon": "10.0.6",
"@types/vscode": "1.63.1",
"@typescript-eslint/eslint-plugin": "5.7.0",
"@typescript-eslint/parser": "5.7.0",
"@vscode/test-electron": "2.0.1",
"all-contributors-cli": "6.20.0",
"assert": "2.0.0",
"buffer": "6.0.3",
"chai": "4.3.4",
"eslint": "^8.5.0",
"eslint-config-prettier": "^8.3.0",
"eslint-config-prettier": "8.3.0",
"eslint": "8.5.0",
"glob": "7.2.0",
"husky": "7.0.4",
"hygen": "6.1.0",
"jest": "27.4.2",
"lint-staged": "^12.1.3",
"jest": "27.4.5",
"lint-staged": "12.1.3",
"mocha": "9.1.3",
"npm-run-all": "4.1.5",
"ovsx": "0.2.1",
"prettier": "2.5.0",
"path-browserify": "1.0.1",
"prettier": "2.5.1",
"pretty-quick": "3.1.3",
"process": "0.11.10",
"sinon": "12.0.1",
"ts-jest": "27.0.7",
"ts-jest": "27.1.2",
"ts-loader": "9.2.6",
"typescript": "4.5.2",
"vsce": "2.5.1",
"webpack": "5.64.4",
"webpack-cli": "4.9.1"
"typescript": "4.5.4",
"util": "0.12.4",
"vsce": "2.6.0",
"webpack-cli": "4.9.1",
"webpack": "5.65.0"
},
"dependencies": {
"@babel/parser": "7.16.4",
"@babel/traverse": "7.16.3",
"@babel/types": "7.16.0",
"@babel/parser": "7.16.7",
"@babel/traverse": "7.16.7",
"@babel/types": "7.16.7",
"@typescript/vfs": "1.3.5",
"change-case": "4.1.2",
"jscodeshift": "0.13.0",
"minimatch": "3.0.4",
"pluralize": "8.0.0",
"react-codemod": "5.4.3",
"recast": "0.20.5",
"ts-morph": "^13.0.2"
"ts-morph": "12.1.0"
},
"resolutions": {
"@babel/types": "7.16.0"
"@babel/types": "7.16.7"
},
"activationEvents": [
"onCommand:abracadabra.addNumericSeparator",
Expand Down
8 changes: 8 additions & 0 deletions src/action-providers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,17 @@ class RefactoringActionProvider implements vscode.CodeActionProvider {
}

const visitorNode = this.getVisitorNode(visitor, path);
// call enter shorthand of e.g. { Identifier() { ... } }
if (typeof visitorNode === "function") {
// @ts-expect-error visitor can expect `NodePath<File>` but `path` is typed as `NodePath<Node>`. It should be OK at runtime.
visitorNode.bind(visitor)(path, path.state);
} else if (typeof visitorNode === "object" && visitorNode !== null) {
// call methods of e.g. { Identifier: { exit() { ... } } }
for (const method of Object.values(visitorNode)) {
if (typeof method === "function") {
method.bind(visitor)(path, path.state);
}
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/ast/scope.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ function isShadowIn(
function findFirstExistingDeclaration(expressionPath: NodePath<t.Expression>) {
const existingDeclarations: NodePath<DestructuredVariableDeclarator>[] =
Object.values(expressionPath.scope.getAllBindings())
.map(({ path }) => path)
.map(({ path }) => path as NodePath)
.filter(
(path): path is NodePath<DestructuredVariableDeclarator> =>
path.isVariableDeclarator() &&
Expand Down
2 changes: 1 addition & 1 deletion src/editor/path.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class Path {
}

get withoutFileName(): string {
return path.dirname(this.value) + path.sep;
return this.value.replace(/[^/]*$/, "");
}

protected get isValueAbsolute(): boolean {
Expand Down
55 changes: 48 additions & 7 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,17 @@
"use strict";

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

/** @returns {import('webpack').Configuration} */
const createConfig = (/** @type {{ browser?: boolean; }} */ env) => ({
// Leaves the source code as close as possible to the original
// (when packaging we set this to 'production')
mode: "none",

/** @type {import('webpack').Configuration} */
const config = {
// vscode extensions run in a Node.js-context
// => https://webpack.js.org/configuration/node/
target: "node",
target: env.browser ? "webworker" : "node",

// => https://webpack.js.org/configuration/entry-context/
entry: "./src/extension.ts",
Expand All @@ -17,7 +22,7 @@ const config = {
// Bundle is stored in the 'out' folder (check package.json)
// => https://webpack.js.org/configuration/output/
path: path.resolve(__dirname, "out"),
filename: "extension.js",
filename: env.browser ? "extension-browser.js" : "extension.js",
libraryTarget: "commonjs2",
devtoolModuleFilenameTemplate: "../[resource-path]"
},
Expand All @@ -32,10 +37,46 @@ const config = {
},

resolve: {
mainFields: ["browser", "module", "main"],
// Support reading TypeScript and JavaScript files
// => https://github.com/TypeStrong/ts-loader
extensions: [".ts", ".js"]
extensions: [".ts", ".js"],
fallback: env.browser
? {
assert: require.resolve("assert"),
buffer: require.resolve("buffer"),
child_process: false,
constants: false,
console: false,
crypto: false,
fs: false,
glob: false,
http: false,
https: false,
os: false,
path: require.resolve("path-browserify"),
stream: false,
unxhr: false,
url: false,
util: require.resolve("util"),
zlib: false
}
: {}
},

plugins: env.browser
? [
new webpack.ProvidePlugin({
process: "process/browser"
}),
// Work around for Buffer is undefined:
// https://github.com/webpack/changelog-v5/issues/10
new webpack.ProvidePlugin({
Buffer: ["buffer", "Buffer"]
})
]
: [],

module: {
rules: [
{
Expand All @@ -49,6 +90,6 @@ const config = {
}
]
}
};
});

module.exports = config;
module.exports = createConfig;
Loading

0 comments on commit 1243a10

Please sign in to comment.