From a97612da72296f6a608522cc6d1f576b7df63817 Mon Sep 17 00:00:00 2001 From: al Date: Tue, 15 Dec 2020 10:26:39 +0800 Subject: [PATCH] fix: package issue. --- .vscodeignore | 24 ++++---- package.json | 11 ++-- src/codingServer.ts | 5 +- src/extension.ts | 2 +- src/tsconfig.json | 2 + webpack.config.extension.js | 57 +++++++++++++++++++ ...ack.config.js => webpack.config.webview.js | 0 7 files changed, 82 insertions(+), 19 deletions(-) create mode 100644 webpack.config.extension.js rename webpack.config.js => webpack.config.webview.js (100%) diff --git a/.vscodeignore b/.vscodeignore index ab3b58f..2e7f70d 100644 --- a/.vscodeignore +++ b/.vscodeignore @@ -1,12 +1,12 @@ -.vscode -node_modules -out/ -src/ -tsconfig.json -webpack.config.js -webviews/ -.gitignore -.editorconfig -.prettierignore -.prettierrc.js -yarn.lock +* +*/** +**/.DS_Store + +!node_modules/vscode-nls/**/* +!node_modules/got/**/* + +!out/**/* +!assets/**/* + +!package.json +!README.md diff --git a/package.json b/package.json index d2ba291..42a1b8b 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "coding-plugin", "description": "Coding plugin for VS Code.", - "version": "0.2.0", + "version": "0.2.1", "publisher": "coding-net", "license": "MIT", "engines": { @@ -120,14 +120,15 @@ "postinstall": "cd src/typings && npx vscode-dts master && npx vscode-dts dev master", "vscode:prepublish": "npm run compile", "compile": "npm-run-all -p compile:*", - "compile:extension": "tsc -p ./src", - "compile:webviews": "webpack --config webpack.config.js", + "compile:extension": "webpack --mode production --config webpack.config.extension.js", + "extension:compile-raw": "tsc -p ./src", + "compile:webviews": "webpack --config webpack.config.webview.js", "watch": "npm-run-all -p watch:*", "watch:extension": "tsc -watch -p ./src", "watch:webviews": "webpack --watch --mode development", "lint": "eslint . --ext .ts,.tsx", - "package": "npx vsce package", - "release": "npx vsce publish" + "package": "npx vsce package --yarn", + "release": "npx vsce publish --yarn" }, "babel": { "plugins": [ diff --git a/src/codingServer.ts b/src/codingServer.ts index 543530b..179d839 100644 --- a/src/codingServer.ts +++ b/src/codingServer.ts @@ -24,6 +24,9 @@ import { IRepoInfo, ISessionData, TokenType } from 'src/typings/commonTypes'; import { keychain } from 'src/common/keychain'; import Logger from 'src/common/logger'; +// @ts-ignore +import * as pkgInfo from '../package.json'; + const AUTH_SERVER = `https://x5p7m.csb.app`; const ClientId = `ff768664c96d04235b1cc4af1e3b37a8`; const ClientSecret = `d29ebb32cab8b5f0a643b5da7dcad8d1469312c7`; @@ -113,7 +116,7 @@ export class CodingServer { public async startOAuth(team: string, scopes: string) { const state = nanoid(); - const { name, publisher } = require('../package.json'); + const { name, publisher } = pkgInfo; const callbackUri = await vscode.env.asExternalUri( vscode.Uri.parse(`${vscode.env.uriScheme}://${publisher}.${name}/on-did-authenticate`), ); diff --git a/src/extension.ts b/src/extension.ts index 9f58929..b92aa04 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -1,4 +1,4 @@ -import 'module-alias/register'; +// import 'module-alias/register'; import * as vscode from 'vscode'; import { uriHandler, CodingServer } from 'src/codingServer'; diff --git a/src/tsconfig.json b/src/tsconfig.json index 5a36cf0..b2e9b33 100644 --- a/src/tsconfig.json +++ b/src/tsconfig.json @@ -2,6 +2,8 @@ "compilerOptions": { "module": "commonjs", "target": "es2019", + "moduleResolution": "Node", + "resolveJsonModule": true, "lib": ["es2019", "dom", "es2020"], "outDir": "../out", "sourceMap": true, diff --git a/webpack.config.extension.js b/webpack.config.extension.js new file mode 100644 index 0000000..6e0a954 --- /dev/null +++ b/webpack.config.extension.js @@ -0,0 +1,57 @@ +/*--------------------------------------------------------------------------------------------- + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for license information. + *--------------------------------------------------------------------------------------------*/ + +//@ts-check + +'use strict'; + +const path = require('path'); + +/**@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'), + 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/ + got: 'got', + keytar: 'keytar', + }, + resolve: { + // support reading TypeScript and JavaScript files, 📖 -> https://github.com/TypeStrong/ts-loader + extensions: ['.ts', '.js'], + alias: { + src: path.resolve(__dirname, 'src'), + }, + }, + module: { + rules: [ + { + test: /\.ts$/, + exclude: /node_modules/, + use: [ + { + loader: 'ts-loader', + options: { + compilerOptions: { + module: 'es6', // override `tsconfig.json` so that TypeScript emits native JavaScript modules. + }, + }, + }, + ], + }, + ], + }, +}; + +module.exports = config; diff --git a/webpack.config.js b/webpack.config.webview.js similarity index 100% rename from webpack.config.js rename to webpack.config.webview.js