Skip to content
This repository has been archived by the owner on Apr 6, 2023. It is now read-only.

Commit

Permalink
refactor: migrate to knitwork
Browse files Browse the repository at this point in the history
  • Loading branch information
danielroe committed Jan 25, 2022
1 parent e52cb3d commit e5b9ea0
Show file tree
Hide file tree
Showing 22 changed files with 34 additions and 17 deletions.
4 changes: 2 additions & 2 deletions packages/bridge/src/vite/templates.ts
Expand Up @@ -2,7 +2,7 @@ import hash from 'hash-sum'
import { resolve } from 'pathe'

import type { Nuxt, NuxtApp } from '@nuxt/schema'
import { genImport, genObjectFromRawEntries } from 'mlly'
import { genImport, genObjectFromRawEntries } from 'knitwork'

type TemplateContext = {
nuxt: Nuxt;
Expand All @@ -25,7 +25,7 @@ export const middlewareTemplate = {
id: m.name || m.src.replace(/[\\/]/g, '/').replace(/\.(js|ts)$/, '')
}
})
return `${_middleware.map(m => genImport(m.filePath,`$${hash(m.id)}` )).join('\n')}
return `${_middleware.map(m => genImport(m.filePath, `$${hash(m.id)}`)).join('\n')}
const middleware = ${genObjectFromRawEntries(_middleware.map(m => [m.id, `$${hash(m.id)}`]))}
export default middleware`
}
Expand Down
1 change: 1 addition & 0 deletions packages/kit/package.json
Expand Up @@ -20,6 +20,7 @@
"globby": "^13.1.0",
"hash-sum": "^2.0.0",
"jiti": "^1.12.9",
"knitwork": "^0.1.0",
"lodash.template": "^4.5.0",
"mlly": "^0.4.0",
"pathe": "^0.2.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/kit/src/components.ts
@@ -1,6 +1,6 @@
import { pascalCase, kebabCase } from 'scule'
import type { ComponentsDir, Component } from '@nuxt/schema'
import { genDynamicImport } from 'mlly'
import { genDynamicImport } from 'knitwork'
import { useNuxt } from './context'
import { assertNuxtCompatibility } from './compatibility'

Expand Down
2 changes: 1 addition & 1 deletion packages/kit/src/internal/template.ts
Expand Up @@ -3,7 +3,7 @@ import lodashTemplate from 'lodash.template'
import hash from 'hash-sum'
import { camelCase } from 'scule'
import { basename, extname } from 'pathe'
import { genDynamicImport, genImport } from 'mlly'
import { genDynamicImport, genImport } from 'knitwork'

import type { NuxtTemplate } from '@nuxt/schema'

Expand Down
1 change: 1 addition & 0 deletions packages/nitro/package.json
Expand Up @@ -48,6 +48,7 @@
"http-proxy": "^1.18.1",
"is-primitive": "^3.0.1",
"jiti": "^1.12.9",
"knitwork": "^0.1.0",
"listhen": "^0.2.6",
"mime": "^3.0.0",
"mlly": "^0.4.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/nitro/src/build.ts
Expand Up @@ -2,7 +2,7 @@ import { relative, resolve, join } from 'pathe'
import consola from 'consola'
import * as rollup from 'rollup'
import fse from 'fs-extra'
import { genDynamicImport } from 'mlly'
import { genDynamicImport } from 'knitwork'
import { printFSTree } from './utils/tree'
import { getRollupConfig } from './rollup/config'
import { hl, prettyPath, serializeTemplate, writeFile, isDirectory, replaceAll } from './utils'
Expand Down
3 changes: 2 additions & 1 deletion packages/nitro/src/rollup/config.ts
Expand Up @@ -17,7 +17,8 @@ import * as unenv from 'unenv'
import devalue from '@nuxt/devalue'

import type { Preset } from 'unenv'
import { sanitizeFilePath, genImport } from 'mlly'
import { sanitizeFilePath } from 'mlly'
import { genImport } from 'knitwork'
import { NitroContext } from '../context'
import { resolvePath } from '../utils'
import { pkgDir } from '../dirs'
Expand Down
2 changes: 1 addition & 1 deletion packages/nitro/src/rollup/plugins/assets.ts
Expand Up @@ -4,7 +4,7 @@ import createEtag from 'etag'
import mime from 'mime'
import { resolve } from 'pathe'
import { globby } from 'globby'
import { genDynamicImport, genObjectFromRawEntries } from 'mlly'
import { genDynamicImport, genObjectFromRawEntries } from 'knitwork'
import virtual from './virtual'

export interface AssetOptions {
Expand Down
2 changes: 1 addition & 1 deletion packages/nitro/src/rollup/plugins/dynamic-require.ts
Expand Up @@ -2,7 +2,7 @@ import { pathToFileURL } from 'url'
import { resolve } from 'pathe'
import { globby } from 'globby'
import type { Plugin } from 'rollup'
import { genDynamicImport, genObjectFromRawEntries, genImport } from 'mlly'
import { genDynamicImport, genObjectFromRawEntries, genImport } from 'knitwork'
import { serializeImportName } from '../../utils'

const PLUGIN_NAME = 'dynamic-require'
Expand Down
2 changes: 1 addition & 1 deletion packages/nitro/src/rollup/plugins/middleware.ts
Expand Up @@ -3,7 +3,7 @@ import { relative } from 'pathe'
import table from 'table'
import isPrimitive from 'is-primitive'
import { isDebug } from 'std-env'
import { genArrayFromRaw, genDynamicImport, genImport } from 'mlly'
import { genArrayFromRaw, genDynamicImport, genImport } from 'knitwork'
import type { ServerMiddleware } from '../../server/middleware'
import virtual from './virtual'

Expand Down
2 changes: 1 addition & 1 deletion packages/nitro/src/rollup/plugins/storage.ts
@@ -1,5 +1,5 @@
import virtual from '@rollup/plugin-virtual'
import { genImport } from 'mlly'
import { genImport } from 'knitwork'
import { serializeImportName } from '../../utils'

export interface StorageOptions {
Expand Down
1 change: 1 addition & 0 deletions packages/nuxt3/build.config.ts
Expand Up @@ -21,6 +21,7 @@ export default defineBuildConfig({
externals: [
'@vue/reactivity',
'@vue/shared',
'knitwork',
'@vueuse/head',
'vue-meta'
]
Expand Down
1 change: 1 addition & 0 deletions packages/nuxt3/package.json
Expand Up @@ -38,6 +38,7 @@
"hash-sum": "^2.0.0",
"hookable": "^5.1.1",
"ignore": "^5.2.0",
"knitwork": "^0.1.0",
"mlly": "^0.4.0",
"murmurhash-es": "^0.1.1",
"nuxi": "3.0.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/nuxt3/src/auto-imports/module.ts
@@ -1,7 +1,7 @@
import { addVitePlugin, addWebpackPlugin, defineNuxtModule, addTemplate, resolveAlias, addPluginTemplate, useNuxt } from '@nuxt/kit'
import type { AutoImportsOptions } from '@nuxt/schema'
import { isAbsolute, join, relative, resolve, normalize } from 'pathe'
import { genDynamicImport } from 'mlly'
import { genDynamicImport } from 'knitwork'
import { TransformPlugin } from './transform'
import { Nuxt3AutoImports } from './imports'
import { scanForComposables } from './composables'
Expand Down
2 changes: 1 addition & 1 deletion packages/nuxt3/src/auto-imports/utils.ts
@@ -1,5 +1,5 @@
import type { AutoImport } from '@nuxt/schema'
import { genExport, genImport } from 'mlly'
import { genExport, genImport } from 'knitwork'

export function toImportModuleMap (autoImports: AutoImport[], isCJS = false) {
const aliasKeyword = isCJS ? ' : ' : ' as '
Expand Down
2 changes: 1 addition & 1 deletion packages/nuxt3/src/components/loader.ts
@@ -1,7 +1,7 @@
import { createUnplugin } from 'unplugin'
import { parseQuery, parseURL } from 'ufo'
import { Component } from '@nuxt/schema'
import { genImport } from 'mlly'
import { genImport } from 'knitwork'

interface LoaderOptions {
getComponents(): Component[]
Expand Down
2 changes: 1 addition & 1 deletion packages/nuxt3/src/components/templates.ts
@@ -1,7 +1,7 @@

import { relative } from 'pathe'
import type { Component } from '@nuxt/schema'
import { genDynamicImport, genObjectFromRawEntries } from 'mlly'
import { genDynamicImport, genObjectFromRawEntries } from 'knitwork'

export type ComponentsTemplateOptions = {
buildDir?: string
Expand Down
2 changes: 1 addition & 1 deletion packages/nuxt3/src/core/templates.ts
@@ -1,6 +1,6 @@
import { templateUtils } from '@nuxt/kit'
import type { Nuxt, NuxtApp } from '@nuxt/schema'
import { genArrayFromRaw, genDynamicImport, genExport, genImport } from 'mlly'
import { genArrayFromRaw, genDynamicImport, genExport, genImport } from 'knitwork'

import { relative } from 'pathe'

Expand Down
2 changes: 1 addition & 1 deletion packages/nuxt3/src/pages/module.ts
@@ -1,7 +1,7 @@
import { existsSync } from 'fs'
import { defineNuxtModule, addTemplate, addPlugin, templateUtils, addVitePlugin, addWebpackPlugin } from '@nuxt/kit'
import { resolve } from 'pathe'
import { genDynamicImport, genObjectFromRawEntries } from 'mlly'
import { genDynamicImport, genObjectFromRawEntries } from 'knitwork'
import { distDir } from '../dirs'
import { resolveLayouts, resolvePagesRoutes, normalizeRoutes, resolveMiddleware, getImportName } from './utils'
import { TransformMacroPlugin, TransformMacroPluginOptions } from './macros'
Expand Down
1 change: 1 addition & 0 deletions packages/vite/package.json
Expand Up @@ -28,6 +28,7 @@
"esbuild": "^0.14.13",
"externality": "^0.1.6",
"fs-extra": "^10.0.0",
"knitwork": "^0.1.0",
"magic-string": "^0.25.7",
"mlly": "^0.4.0",
"p-debounce": "^4.0.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/vite/src/dev-bundler.ts
Expand Up @@ -4,7 +4,7 @@ import { builtinModules } from 'module'
import { resolve } from 'pathe'
import * as vite from 'vite'
import { ExternalsOptions, isExternal as _isExternal, ExternalsDefaults } from 'externality'
import { genDynamicImport, genObjectFromRawEntries } from 'mlly'
import { genDynamicImport, genObjectFromRawEntries } from 'knitwork'
import { hashId, uniq } from './utils'

export interface TransformChunk {
Expand Down
11 changes: 11 additions & 0 deletions yarn.lock
Expand Up @@ -2871,6 +2871,7 @@ __metadata:
globby: ^13.1.0
hash-sum: ^2.0.0
jiti: ^1.12.9
knitwork: ^0.1.0
lodash.template: ^4.5.0
mlly: ^0.4.0
pathe: ^0.2.0
Expand Down Expand Up @@ -2965,6 +2966,7 @@ __metadata:
http-proxy: ^1.18.1
is-primitive: ^3.0.1
jiti: ^1.12.9
knitwork: ^0.1.0
listhen: ^0.2.6
mime: ^3.0.0
mlly: ^0.4.0
Expand Down Expand Up @@ -3234,6 +3236,7 @@ __metadata:
esbuild: ^0.14.13
externality: ^0.1.6
fs-extra: ^10.0.0
knitwork: ^0.1.0
magic-string: ^0.25.7
mlly: ^0.4.0
p-debounce: ^4.0.0
Expand Down Expand Up @@ -13784,6 +13787,13 @@ __metadata:
languageName: node
linkType: hard

"knitwork@npm:^0.1.0":
version: 0.1.0
resolution: "knitwork@npm:0.1.0"
checksum: 36782ee8fcfb78a18684ff28ab6e829381d45a02cb8eb9efa192b3c521d9f6ff6d1ba3fbc28bdae471a9d251821ea99018a1f3e224e7b3cb62f72bbdb3a4cbd6
languageName: node
linkType: hard

"kolorist@npm:^1.5.0":
version: 1.5.1
resolution: "kolorist@npm:1.5.1"
Expand Down Expand Up @@ -15841,6 +15851,7 @@ __metadata:
hash-sum: ^2.0.0
hookable: ^5.1.1
ignore: ^5.2.0
knitwork: ^0.1.0
mlly: ^0.4.0
murmurhash-es: ^0.1.1
nuxi: 3.0.0
Expand Down

0 comments on commit e5b9ea0

Please sign in to comment.