Skip to content

Commit

Permalink
chore: bump deps
Browse files Browse the repository at this point in the history
  • Loading branch information
nonzzz committed Oct 20, 2023
1 parent 347e7ec commit 2add410
Show file tree
Hide file tree
Showing 23 changed files with 603 additions and 432 deletions.
2 changes: 0 additions & 2 deletions .eslintignore

This file was deleted.

3 changes: 0 additions & 3 deletions .eslintrc.js

This file was deleted.

4 changes: 4 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"eslint.experimental.useFlatConfig": true
}

4 changes: 0 additions & 4 deletions __tests__/code-gen.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { createCodeGenerator } from '../src/code-gen'
import { createScanner } from '../dist/scanner'
import type { ModuleInfo } from '../src/interface'


test('filter', async (t) => {
const code = `
import { ref } from 'vue';
Expand Down Expand Up @@ -172,7 +171,6 @@ test('export with declaration', async (t) => {
t.is(res.code, 'export const value = Vue.ref(0);')
})


test('export all module but the current module itself contains duplicated node', async (t) => {
const code = 'export * from \'vue\';\nexport const version = \'self\';'
const scanner = createScanner(['vue'])
Expand All @@ -192,5 +190,3 @@ test('import sub module', async (t) => {
const res = await codeGen.transform(code)
t.is(res.code, 'console.log(Vue.ref);')
})


1 change: 0 additions & 1 deletion __tests__/fixtures/cdn-plugin/main.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable */
import { createApp, createVNode, defineComponent } from 'vue'

const App = defineComponent({
Expand Down
2 changes: 1 addition & 1 deletion __tests__/inject.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { createInjectScript } from '../src/inject'
import { jsdelivr } from '../src/url'
import type { TrackModule } from '../src'

interface MockIIFEMdoule extends TrackModule{
interface MockIIFEMdoule extends TrackModule {
relativeModule: string
version: string
bindings: Set<string>
Expand Down
2 changes: 1 addition & 1 deletion __tests__/plugin.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ test('exteranl plugin', async (t) => {

const { code } = bundle[0].output[0]
const global = /Vue(.)\w+/g
const [s, s1] = code.match(global)
const [s, s1] = code.match(global)
t.is(s, 'Vue.defineComponent')
t.is(s1, 'Vue.createVNode')
})
Expand Down
1 change: 0 additions & 1 deletion __tests__/scanner.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ test('scanner failed', (t) => {
t.is(scanner.dependencies.has('vue'), true)
})


test('scanner with resolver', (t) => {
const scanner = createScanner([{ name: 'vue', resolve: (p) => p }])
scanner.scanAllDependencies()
Expand Down
3 changes: 1 addition & 2 deletions __tests__/shared.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@ import fsp from 'fs/promises'
import test from 'ava'
import { MAX_CONCURRENT, createConcurrentQueue, len, lookup } from '../src/shared'


test('len', (t) => {
t.is(len('123'), 3)
t.is(len([1, 2, 3, 4, 5]), 5)
})

test('lookup', async (t) => {
const modulePath = require.resolve('vue')
const modulePath = require.resolve('vue')
const file = lookup(modulePath, 'package.json')
const s = await fsp.readFile(file, 'utf8')
const p = JSON.parse(s)
Expand Down
14 changes: 6 additions & 8 deletions e2e/e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,13 @@ import type { Vite4Instance } from './vite4/interface'
type ViteInstance = Vite2Instance | Vite3Instance | Vite4Instance

export interface TestOptions {
vite: ViteInstance
pluginOption?: Parameters<typeof cdn>[number],
plugins: any[]
vite: ViteInstance
pluginOption?: Parameters<typeof cdn>[number],
plugins: any[]
}


type Server = http.Server & {
ip: string
ip: string
}

const defaultWd = __dirname
Expand All @@ -38,7 +37,7 @@ function prepareAssets(taskName: string, options: TestOptions) {
})
}

function createGetter<T>(obj: T, key: string, getter: ()=> unknown) {
function createGetter<T>(obj: T, key: string, getter: () => unknown) {
Object.defineProperty(obj, key, {
get: getter
})
Expand Down Expand Up @@ -73,8 +72,7 @@ function createServer(taskName: string) {
const readStream = fs.createReadStream(fullPath)
res.setHeader('Content-Type', contentType)
res.statusCode = 200
readStream.pipe(res)
return
readStream.pipe(res)
}
} catch (error) {
res.statusCode = 404
Expand Down
3 changes: 3 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const { nonzzz } = require('eslint-config-kagura')

module.exports = nonzzz({ ts: true, jsx: true, react: true }, { ignores: ['dist', 'node_modules'] })
1 change: 0 additions & 1 deletion examples/react/src/main.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable */
import React from 'react'
import ReactDOM from 'react-dom/client'
import { App } from './app'
Expand Down
1 change: 0 additions & 1 deletion examples/vue3/components.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable */
/* prettier-ignore */
// @ts-nocheck
// Generated by unplugin-vue-components
Expand Down
1 change: 0 additions & 1 deletion examples/vue3/src/api.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable */
export { ref as default, onMounted, watchEffect } from 'vue'
export * as vue from 'vue'

Expand Down
60 changes: 54 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,10 @@
"@types/babel__core": "^7.20.1",
"@types/debug": "^4.1.8",
"@types/node": "^20.5.0",
"@typescript-eslint/eslint-plugin": "^6.4.1",
"@typescript-eslint/parser": "^6.4.1",
"ava": "^5.2.0",
"c8": "^7.12.0",
"eslint": "^8.23.1",
"eslint-config-kagura": "^1.2.0",
"eslint-plugin-import": "npm:eslint-plugin-i@2.28.0-2",
"eslint": "^8.51.0",
"eslint-config-kagura": "^2.0.0",
"playwright": "^1.35.1",
"tsup": "^7.1.0",
"typescript": "^4.8.3",
Expand All @@ -97,7 +94,58 @@
},
"resolutions": {
"function-bind": "npm:@nolyfill/function-bind@latest",
"has": "npm:@nolyfill/has@latest"
"has": "npm:@nolyfill/has@latest",
"array-buffer-byte-length": "npm:@nolyfill/array-buffer-byte-length@latest",
"array-includes": "npm:@nolyfill/array-includes@latest",
"array.prototype.flat": "npm:@nolyfill/array.prototype.flat@latest",
"array.prototype.flatmap": "npm:@nolyfill/array.prototype.flatmap@latest",
"array.prototype.tosorted": "npm:@nolyfill/array.prototype.tosorted@latest",
"arraybuffer.prototype.slice": "npm:@nolyfill/arraybuffer.prototype.slice@latest",
"asynciterator.prototype": "npm:@nolyfill/asynciterator.prototype@latest",
"available-typed-arrays": "npm:@nolyfill/available-typed-arrays@latest",
"define-properties": "npm:@nolyfill/define-properties@latest",
"es-iterator-helpers": "npm:@nolyfill/es-iterator-helpers@latest",
"es-set-tostringtag": "npm:@nolyfill/es-set-tostringtag@latest",
"function.prototype.name": "npm:@nolyfill/function.prototype.name@latest",
"get-symbol-description": "npm:@nolyfill/get-symbol-description@latest",
"globalthis": "npm:@nolyfill/globalthis@latest",
"gopd": "npm:@nolyfill/gopd@latest",
"has-property-descriptors": "npm:@nolyfill/has-property-descriptors@latest",
"has-proto": "npm:@nolyfill/has-proto@latest",
"has-symbols": "npm:@nolyfill/has-symbols@latest",
"has-tostringtag": "npm:@nolyfill/has-tostringtag@latest",
"internal-slot": "npm:@nolyfill/internal-slot@latest",
"is-array-buffer": "npm:@nolyfill/is-array-buffer@latest",
"is-date-object": "npm:@nolyfill/is-date-object@latest",
"is-generator-function": "npm:@nolyfill/is-generator-function@latest",
"is-regex": "npm:@nolyfill/is-regex@latest",
"is-shared-array-buffer": "npm:@nolyfill/is-shared-array-buffer@latest",
"is-string": "npm:@nolyfill/is-string@latest",
"is-symbol": "npm:@nolyfill/is-symbol@latest",
"is-weakref": "npm:@nolyfill/is-weakref@latest",
"iterator.prototype": "npm:@nolyfill/iterator.prototype@latest",
"object-keys": "npm:@nolyfill/object-keys@latest",
"object.assign": "npm:@nolyfill/object.assign@latest",
"object.entries": "npm:@nolyfill/object.entries@latest",
"object.fromentries": "npm:@nolyfill/object.fromentries@latest",
"object.hasown": "npm:@nolyfill/object.hasown@latest",
"object.values": "npm:@nolyfill/object.values@latest",
"reflect.getprototypeof": "npm:@nolyfill/reflect.getprototypeof@latest",
"regexp.prototype.flags": "npm:@nolyfill/regexp.prototype.flags@latest",
"safe-array-concat": "npm:@nolyfill/safe-array-concat@latest",
"safe-regex-test": "npm:@nolyfill/safe-regex-test@latest",
"side-channel": "npm:@nolyfill/side-channel@latest",
"string.prototype.matchall": "npm:@nolyfill/string.prototype.matchall@latest",
"string.prototype.trim": "npm:@nolyfill/string.prototype.trim@latest",
"string.prototype.trimend": "npm:@nolyfill/string.prototype.trimend@latest",
"string.prototype.trimstart": "npm:@nolyfill/string.prototype.trimstart@latest",
"typed-array-buffer": "npm:@nolyfill/typed-array-buffer@latest",
"typed-array-byte-length": "npm:@nolyfill/typed-array-byte-length@latest",
"typed-array-byte-offset": "npm:@nolyfill/typed-array-byte-offset@latest",
"typed-array-length": "npm:@nolyfill/typed-array-length@latest",
"unbox-primitive": "npm:@nolyfill/unbox-primitive@latest",
"which-boxed-primitive": "npm:@nolyfill/which-boxed-primitive@latest",
"which-typed-array": "npm:@nolyfill/which-typed-array@latest"
},
"packageManager": "yarn@3.6.3"
}
4 changes: 1 addition & 3 deletions src/code-gen.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { parse as esModuleLexer } from 'rs-module-lexer'
import { parse as babelParse, types as t, transformFromAstAsync, traverse } from '@babel/core'
import { parse as babelParse, types as t, transformFromAstAsync, traverse } from '@babel/core'
import type { NodePath } from '@babel/core'
import { len } from './shared'
import type { ModuleInfo } from './interface'


function isTopLevelCalled(p: NodePath) {
return t.isProgram(p.parent) || t.isExportDefaultDeclaration(p.parent) || t.isExportNamedDeclaration(p.parent)
}
Expand Down Expand Up @@ -307,7 +306,6 @@ export class CodeGen {
}
}


export function createCodeGenerator() {
return new CodeGen()
}
Expand Down
7 changes: 3 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,19 @@ import type { Plugin } from 'vite'
import _debug from 'debug'
import { createScanner, getPackageExports, serializationExportsFields } from './scanner'
import { createInjectScript } from './inject'
import { createCodeGenerator } from './code-gen'
import { isSupportThreads, transformCJSRequire } from './shared'
import { createCodeGenerator } from './code-gen'
import { isSupportThreads, transformCJSRequire } from './shared'
import { jsdelivr } from './url'
import type { CodeGen } from './code-gen'
import type { CDNPluginOptions, ExternalPluginOptions, ModuleInfo } from './interface'

const debug = _debug('vite-plugin-cdn2')

interface ExternalPluginAPI {
filter: (id: unknown)=> boolean
filter: (id: unknown) => boolean
generator: CodeGen
}


function transformPresetModule(api: ExternalPluginAPI): Plugin {
// Inspired by vite-plugin-external
const nodeModules = 'node_modules'
Expand Down
1 change: 0 additions & 1 deletion src/inject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ class InjectScript {
return tags
}


calledHook(transformHook?: CDNPluginOptions['transform']) {
if (transformHook) {
const hook = transformHook()
Expand Down
29 changes: 14 additions & 15 deletions src/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export interface Module {
global?: string
}

export interface TrackModule extends Module{
export interface TrackModule extends Module {
spare?: Array<string> | string
relativeModule?: string
aliases?: Array<string>
Expand All @@ -17,7 +17,7 @@ export interface IIFEModuleInfo extends TrackModule {
jsdelivr?: string
}

export type ResolverFunction = (p: string, extra: IIFEModuleInfo)=> string
export type ResolverFunction = (p: string, extra: IIFEModuleInfo) => string

export interface ModuleInfo extends IIFEModuleInfo {
bindings: Set<string>
Expand All @@ -41,7 +41,6 @@ export interface Serialization {
extra: Record<string, any>
}


export type ScriptAttributes = Partial<
Pick<
HTMLScriptElement,
Expand All @@ -68,31 +67,31 @@ export type LinkAttrobites = Partial<
>

export type ScriptNode = ScriptAttributes &
Omit<Serialization, 'tag' | 'type'> & {
tag: 'script'
}
Omit<Serialization, 'tag' | 'type'> & {
tag: 'script'
}

export type LinkNode = LinkAttrobites &
Omit<Serialization, 'tag' | 'type'> & {
tag: 'link'
}
Omit<Serialization, 'tag' | 'type'> & {
tag: 'link'
}

export interface InjectVisitor {
script?: (node: ScriptNode)=> void
link?: (node: LinkNode)=> void
script?: (node: ScriptNode) => void
link?: (node: LinkNode) => void
}

type Pretty<T> = {
[key in keyof T]:
T[key] extends (...args: any[])=> any
? (...args: Parameters<T[key]>)=> ReturnType<T[key]>
: T[key] & NonNullable<unknown>
T[key] extends (...args: any[]) => any
? (...args: Parameters<T[key]>) => ReturnType<T[key]>
: T[key] & NonNullable<unknown>
} & NonNullable<unknown>

export type CDNPluginOptions = Pretty<{
modules?: Array<IModule | string>
url?: string
transform?: ()=> InjectVisitor
transform?: () => InjectVisitor
include?: FilterPattern
exclude?: FilterPattern
logLevel?: 'slient' | 'warn'
Expand Down
Loading

0 comments on commit 2add410

Please sign in to comment.