Skip to content

Commit

Permalink
refactor: move source scripts from src to lib (#3913)
Browse files Browse the repository at this point in the history
  • Loading branch information
johnsoncodehk committed Mar 1, 2024
1 parent 3fa6c1f commit 79e224d
Show file tree
Hide file tree
Showing 96 changed files with 154 additions and 161 deletions.
7 changes: 7 additions & 0 deletions .gitignore
Expand Up @@ -6,3 +6,10 @@ node_modules
.vscode-test-web
extensions/*/meta.json
extensions/*/stats.html

packages/*/*.d.ts
packages/*/*.js
packages/*/*.map
packages/*/lib/**/*.d.ts
packages/*/lib/**/*.js
packages/*/lib/**/*.map
9 changes: 6 additions & 3 deletions .vscode/launch.json
Expand Up @@ -12,7 +12,8 @@
"--extensionDevelopmentPath=${workspaceRoot}/extensions/vscode"
],
"outFiles": [
"${workspaceRoot}/*/*/out/**/*.js"
"${workspaceRoot}/*/*/*.js",
"${workspaceRoot}/*/*/lib/**/*.js"
],
"preLaunchTask": {
"type": "npm",
Expand All @@ -30,7 +31,8 @@
"--extensionDevelopmentKind=web"
],
"outFiles": [
"${workspaceRoot}/*/*/out/**/*.js"
"${workspaceRoot}/*/*/*.js",
"${workspaceRoot}/*/*/lib/**/*.js"
],
"preLaunchTask": {
"type": "npm",
Expand All @@ -44,7 +46,8 @@
"port": 6009,
"restart": true,
"outFiles": [
"${workspaceRoot}/*/*/out/**/*.js"
"${workspaceRoot}/*/*/*.js",
"${workspaceRoot}/*/*/lib/**/*.js"
]
}
],
Expand Down
8 changes: 8 additions & 0 deletions .vscode/settings.json
Expand Up @@ -17,4 +17,12 @@
"editor.defaultFormatter": "vscode.json-language-features"
},
"vue.server.path": "./extensions/vscode/server.js",
"files.exclude": {
"packages/*/*.d.ts": true,
"packages/*/*.js": true,
"packages/*/*.map": true,
"packages/*/lib/**/*.d.ts": true,
"packages/*/lib/**/*.js": true,
"packages/*/lib/**/*.map": true
}
}
2 changes: 1 addition & 1 deletion extensions/vscode/scripts/build.js
Expand Up @@ -64,7 +64,7 @@ require('esbuild').context({
})

require('esbuild').context({
entryPoints: ['./node_modules/@vue/typescript-plugin/out/index.js'],
entryPoints: ['./node_modules/@vue/typescript-plugin/index.js'],
bundle: true,
outfile: './node_modules/typescript-vue-plugin-bundle/index.js',
external: ['vscode'],
Expand Down
2 changes: 1 addition & 1 deletion extensions/vscode/src/common.ts
Expand Up @@ -7,7 +7,7 @@ import {
} from '@volar/vscode';
import { DiagnosticModel, VueInitializationOptions } from '@vue/language-server';
import * as vscode from 'vscode';
import * as lsp from 'vscode-languageclient';
import type * as lsp from 'vscode-languageclient';
import { config } from './config';
import * as doctor from './features/doctor';
import * as nameCasing from './features/nameCasing';
Expand Down
8 changes: 4 additions & 4 deletions extensions/vscode/src/features/doctor.ts
@@ -1,8 +1,8 @@
import * as vscode from 'vscode';
import * as semver from 'semver';
import { BaseLanguageClient } from 'vscode-languageclient';
import { ParseSFCRequest } from '@vue/language-server';
import { getTsdk } from '@volar/vscode';
import { ParseSFCRequest } from '@vue/language-server';
import * as semver from 'semver';
import * as vscode from 'vscode';
import type { BaseLanguageClient } from 'vscode-languageclient';
import { config } from '../config';

const scheme = 'vue-doctor';
Expand Down
4 changes: 2 additions & 2 deletions extensions/vscode/src/features/splitEditors.ts
@@ -1,6 +1,6 @@
import * as vscode from 'vscode';
import { BaseLanguageClient } from 'vscode-languageclient';
import { ParseSFCRequest } from '@vue/language-server';
import * as vscode from 'vscode';
import type { BaseLanguageClient } from 'vscode-languageclient';
import { config } from '../config';

type SFCBlock = ParseSFCRequest.ResponseType['descriptor']['customBlocks'][number];
Expand Down
4 changes: 2 additions & 2 deletions extensions/vscode/src/middleware.ts
@@ -1,7 +1,7 @@
import { AttrNameCasing, TagNameCasing } from '@vue/language-server';
import { middleware as baseMiddleware } from '@volar/vscode';
import { AttrNameCasing, TagNameCasing } from '@vue/language-server';
import * as vscode from 'vscode';
import * as lsp from 'vscode-languageclient';
import type * as lsp from 'vscode-languageclient';
import { attrNameCasings, tagNameCasings } from './features/nameCasing';

export const middleware: lsp.Middleware = {
Expand Down
@@ -1,8 +1,8 @@
import * as ts from 'typescript';
import { createCheckerByJsonConfigBase, createCheckerBase } from './base';
import type { MetaCheckerOptions } from './types';
import { createCheckerByJsonConfigBase, createCheckerBase } from './lib/base';
import type { MetaCheckerOptions } from './lib/types';

export * from './types';
export * from './lib/types';

/**
* @deprecated Use `createCheckerByJson` instead.
Expand Down
File renamed without changes.
File renamed without changes.
1 change: 0 additions & 1 deletion packages/component-meta/package.json
@@ -1,7 +1,6 @@
{
"name": "vue-component-meta",
"version": "1.8.27",
"main": "out/index.js",
"license": "MIT",
"files": [
"out/**/*.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/component-meta/tests/index.spec.ts
@@ -1,6 +1,6 @@
import * as path from 'path';
import { describe, expect, test } from 'vitest';
import { createComponentMetaChecker, createComponentMetaCheckerByJsonConfig, MetaCheckerOptions, ComponentMetaChecker, TypeMeta } from '../out';
import { createComponentMetaChecker, createComponentMetaCheckerByJsonConfig, MetaCheckerOptions, ComponentMetaChecker, TypeMeta } from '..';

const worker = (checker: ComponentMetaChecker, withTsconfig: boolean) => describe(`vue-component-meta ${withTsconfig ? 'with tsconfig' : 'without tsconfig'}`, () => {

Expand Down
7 changes: 2 additions & 5 deletions packages/component-meta/tsconfig.json
@@ -1,10 +1,7 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"outDir": "out",
"rootDir": "src",
},
"include": [ "src" ],
"include": [ "*", "lib/**/*" ],
"exclude": [ "tests" ],
"references": [
{ "path": "../language-core/tsconfig.json" },
],
Expand Down
15 changes: 15 additions & 0 deletions packages/language-core/index.ts
@@ -0,0 +1,15 @@
export * from './lib/generators/template';
export * from './lib/languageModule';
export * from './lib/parsers/scriptSetupRanges';
export * from './lib/plugins';
export * from './lib/virtualFile/vueFile';
export * from './lib/types';
export * from './lib/utils/ts';
export * from './lib/utils/parseSfc';

export * as scriptRanges from './lib/parsers/scriptRanges';
export * from './lib/utils/shared';
export { tsCodegen } from './lib/plugins/vue-tsx';

export * from '@volar/language-core';
export type * as CompilerDOM from '@vue/compiler-dom';
@@ -1,10 +1,9 @@
import { Mapping } from '@volar/language-core';
import type { Mapping } from '@volar/language-core';
import * as path from 'path-browserify';
import type * as ts from 'typescript';
import type { ScriptRanges } from '../parsers/scriptRanges';
import type { ScriptSetupRanges } from '../parsers/scriptSetupRanges';
import type { Code, CodeAndStack, SfcBlock, VueCompilerOptions } from '../types';
import { Sfc } from '../types';
import type { Code, CodeAndStack, Sfc, SfcBlock, VueCompilerOptions } from '../types';
import { getSlotsPropertyName, hyphenateTag } from '../utils/shared';
import { eachInterpolationSegment } from '../utils/transform';
import { disableAllFeatures, enableAllFeatures, withStack } from './utils';
Expand Down
Expand Up @@ -3,7 +3,7 @@ import * as CompilerDOM from '@vue/compiler-dom';
import { camelize, capitalize } from '@vue/shared';
import { minimatch } from 'minimatch';
import type * as ts from 'typescript';
import { Code, CodeAndStack, Sfc, VueCodeInformation, VueCompilerOptions } from '../types';
import type { Code, CodeAndStack, Sfc, VueCodeInformation, VueCompilerOptions } from '../types';
import { hyphenateAttr, hyphenateTag } from '../utils/shared';
import { collectVars, eachInterpolationSegment } from '../utils/transform';
import { disableAllFeatures, enableAllFeatures, getStack, mergeFeatureSettings } from './utils';
Expand Down
@@ -1,4 +1,4 @@
import { Code, CodeAndStack, VueCodeInformation } from '../types';
import type { Code, CodeAndStack, VueCodeInformation } from '../types';

export function withStack(code: Code): CodeAndStack {
return [code, getStack()];
Expand Down
@@ -1,9 +1,9 @@
import { forEachEmbeddedCode, type LanguagePlugin } from '@volar/language-core';
import { getDefaultVueLanguagePlugins, createPluginContext } from './plugins';
import { VueGeneratedCode } from './virtualFile/vueFile';
import { VueCompilerOptions, VueLanguagePlugin } from './types';
import type * as ts from 'typescript';
import { createPluginContext, getDefaultVueLanguagePlugins } from './plugins';
import type { VueCompilerOptions, VueLanguagePlugin } from './types';
import { resolveVueCompilerOptions } from './utils/ts';
import { VueGeneratedCode } from './virtualFile/vueFile';

const fileRegistries: {
key: string;
Expand Down
@@ -1,3 +1,4 @@
import * as CompilerDOM from '@vue/compiler-dom';
import type * as ts from 'typescript';
import useHtmlFilePlugin from './plugins/file-html';
import useMdFilePlugin from './plugins/file-md';
Expand All @@ -8,8 +9,7 @@ import useVueSfcStyles from './plugins/vue-sfc-styles';
import useVueSfcTemplate from './plugins/vue-sfc-template';
import useHtmlTemplatePlugin from './plugins/vue-template-html';
import useVueTsx from './plugins/vue-tsx';
import { VueCompilerOptions, VueLanguagePlugin } from './types';
import * as CompilerDOM from '@vue/compiler-dom';
import type { VueCompilerOptions, VueLanguagePlugin } from './types';
import * as CompilerVue2 from './utils/vue2TemplateCompiler';

export function createPluginContext(
Expand Down
@@ -1,5 +1,5 @@
import type { SFCParseResult } from '@vue/compiler-sfc';
import { VueLanguagePlugin } from '../types';
import type { VueLanguagePlugin } from '../types';

const sfcBlockReg = /\<(script|style)\b([\s\S]*?)\>([\s\S]*?)\<\/\1\>/g;
const langReg = /\blang\s*=\s*(['\"]?)(\S*)\b\1/;
Expand Down
@@ -1,6 +1,6 @@
import { buildMappings, Segment, SourceMap, toString } from '@volar/language-core';
import type { SFCBlock } from '@vue/compiler-sfc';
import { VueLanguagePlugin } from '../types';
import type { VueLanguagePlugin } from '../types';
import { parse } from '../utils/parseSfc';

const codeblockReg = /(`{3,})[\s\S]+?\1/g;
Expand Down
@@ -1,4 +1,4 @@
import { VueLanguagePlugin } from '../types';
import type { VueLanguagePlugin } from '../types';
import { parse } from '../utils/parseSfc';

const plugin: VueLanguagePlugin = (_ctx) => {
Expand Down
@@ -1,5 +1,5 @@
import { enableAllFeatures } from '../generators/utils';
import { VueLanguagePlugin } from '../types';
import type { VueLanguagePlugin } from '../types';

const plugin: VueLanguagePlugin = () => {

Expand Down
@@ -1,5 +1,5 @@
import { disableAllFeatures } from '../generators/utils';
import { VueLanguagePlugin } from '../types';
import type { VueLanguagePlugin } from '../types';

const plugin: VueLanguagePlugin = () => {

Expand Down
@@ -1,5 +1,5 @@
import { enableAllFeatures } from '../generators/utils';
import { VueLanguagePlugin } from '../types';
import type { VueLanguagePlugin } from '../types';

const plugin: VueLanguagePlugin = () => {

Expand Down
@@ -1,5 +1,5 @@
import { enableAllFeatures } from '../generators/utils';
import { VueLanguagePlugin } from '../types';
import type { VueLanguagePlugin } from '../types';

const plugin: VueLanguagePlugin = () => {

Expand Down
@@ -1,5 +1,5 @@
import { VueLanguagePlugin } from '../types';
import type * as CompilerDOM from '@vue/compiler-dom';
import type { VueLanguagePlugin } from '../types';

interface Loc {
start: { offset: number; };
Expand Down
Expand Up @@ -2,10 +2,10 @@ import { CodeInformation, Mapping, Segment, StackNode, track } from '@volar/lang
import { computed, computedSet } from 'computeds';
import { generate as generateScript } from '../generators/script';
import { generate as generateTemplate } from '../generators/template';
import { enableAllFeatures } from '../generators/utils';
import { parseScriptRanges } from '../parsers/scriptRanges';
import { parseScriptSetupRanges } from '../parsers/scriptSetupRanges';
import { Code, Sfc, VueLanguagePlugin } from '../types';
import { enableAllFeatures } from '../generators/utils';
import type { Code, Sfc, VueLanguagePlugin } from '../types';

export const tsCodegen = new WeakMap<Sfc, ReturnType<typeof createTsx>>();

Expand Down
File renamed without changes.
File renamed without changes.
@@ -1,7 +1,7 @@
import { isGloballyWhitelisted } from '@vue/shared';
import type * as ts from 'typescript';
import { VueCompilerOptions } from '../types';
import { getNodeText, getStartEnd } from '../parsers/scriptSetupRanges';
import type { VueCompilerOptions } from '../types';

export function* eachInterpolationSegment(
ts: typeof import('typescript'),
Expand Down
File renamed without changes.
Expand Up @@ -2,7 +2,7 @@ import { Mapping, Segment, replaceSourceRange } from '@volar/language-core';
import { computed } from 'computeds';
import type * as ts from 'typescript';
import { enableAllFeatures } from '../generators/utils';
import { Sfc, VueCodeInformation } from '../types';
import type { Sfc, VueCodeInformation } from '../types';

export function computedMappings(
snapshot: () => ts.IScriptSnapshot,
Expand Down
@@ -1,10 +1,10 @@
import type * as CompilerDOM from '@vue/compiler-dom';
import type { SFCBlock, SFCParseResult } from '@vue/compiler-sfc';
import { computed, computedArray, pauseTracking, resetTracking } from 'computeds';
import type * as ts from 'typescript';
import { Sfc, SfcBlock, VueLanguagePlugin } from '../types';
import type { Sfc, SfcBlock, VueLanguagePlugin } from '../types';
import { parseCssClassNames } from '../utils/parseCssClassNames';
import { parseCssVars } from '../utils/parseCssVars';
import { computed, pauseTracking, resetTracking, computedArray } from 'computeds';

export function computedSfc(
ts: typeof import('typescript'),
Expand Down
@@ -1,7 +1,7 @@
import type { SFCParseResult } from '@vue/compiler-sfc';
import type * as ts from 'typescript';
import { VueLanguagePlugin } from '../types';
import { computed } from 'computeds';
import type * as ts from 'typescript';
import type { VueLanguagePlugin } from '../types';

export function computedVueSfc(
plugins: ReturnType<VueLanguagePlugin>[],
Expand Down
@@ -1,5 +1,5 @@
import { Mapping, StackNode } from '@volar/language-core';
import { Code } from '../types';
import type { Mapping, StackNode } from '@volar/language-core';
import type { Code } from '../types';

export class VueEmbeddedFile {

Expand Down
@@ -1,11 +1,11 @@
import { Stack, VirtualCode } from '@volar/language-core';
import type { Stack, VirtualCode } from '@volar/language-core';
import { Signal, signal } from 'computeds';
import type * as ts from 'typescript';
import { VueCompilerOptions, VueLanguagePlugin } from '../types';
import type { VueCompilerOptions, VueLanguagePlugin } from '../types';
import { computedFiles } from './computedFiles';
import { computedMappings } from './computedMappings';
import { computedSfc } from './computedSfc';
import { computedVueSfc } from './computedVueSfc';
import { Signal, signal } from 'computeds';

export class VueGeneratedCode implements VirtualCode {

Expand Down
1 change: 0 additions & 1 deletion packages/language-core/package.json
@@ -1,7 +1,6 @@
{
"name": "@vue/language-core",
"version": "1.8.27",
"main": "out/index.js",
"license": "MIT",
"files": [
"out/**/*.js",
Expand Down
15 changes: 0 additions & 15 deletions packages/language-core/src/index.ts

This file was deleted.

7 changes: 2 additions & 5 deletions packages/language-core/tsconfig.json
@@ -1,8 +1,5 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"outDir": "out",
"rootDir": "src",
},
"include": [ "src" ],
"include": [ "*", "lib/**/*" ],
"exclude": [ "tests" ],
}
File renamed without changes.
1 change: 0 additions & 1 deletion packages/language-plugin-pug/package.json
@@ -1,7 +1,6 @@
{
"name": "@vue/language-plugin-pug",
"version": "1.8.27",
"main": "out/index.js",
"license": "MIT",
"files": [
"out/**/*.js",
Expand Down

0 comments on commit 79e224d

Please sign in to comment.