Skip to content

Commit

Permalink
feat: upgrade to "type": "module"
Browse files Browse the repository at this point in the history
  • Loading branch information
mesqueeb committed Feb 4, 2022
1 parent f0b279e commit 97f798a
Show file tree
Hide file tree
Showing 15 changed files with 1,651 additions and 2,920 deletions.
4,328 changes: 1,533 additions & 2,795 deletions package-lock.json

Large diffs are not rendered by default.

11 changes: 7 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,23 @@
"build": "rollup -c ./build/buildScripts.js",
"build-and-commit": "npm run build && git add -A && git commit -m \"chore: build\"",
"copy:readme": "copyfiles 'README.md' packages/vue-intellisense",
"dep:update-all": "ncu --target minor -u && lerna exec 'ncu --target minor -u' && npm i",
"dep:update-all": "ncu -u && lerna exec 'ncu -u' && npm i",
"dep:check-for-updates": "ncu --target minor && lerna exec 'ncu --target minor'",
"dep:reinstall-all": "rimraf node_modules && lerna clean -y && npm i",
"test:scripts": "cd packages/scripts && npm run test",
"publish": "npm run copy:readme && npm run build-and-commit && lerna publish"
},
"devDependencies": {
"@types/fs-extra": "^9.0.13",
"copyfiles": "^2.4.1",
"lerna": "^4.0.0",
"lerna-audit": "^1.3.3",
"npm-check-updates": "^12.2.1",
"rollup": "^2.66.0",
"rollup-plugin-typescript2": "^0.31.1",
"typescript": "^4.5.5"
"rimraf": "^3.0.2",
"rollup": "^2.67.0",
"rollup-plugin-typescript2": "^0.31.2",
"typescript": "^4.5.5",
"vitest": "^0.2.7"
},
"license": "MIT",
"homepage": "https://github.com/cycraft/vue-intellisense#readme",
Expand Down
33 changes: 12 additions & 21 deletions packages/scripts/package.json
Original file line number Diff line number Diff line change
@@ -1,32 +1,23 @@
{
"name": "@vue-intellisense/scripts",
"version": "0.3.1",
"type": "module",
"main": "dist/index.cjs.js",
"module": "dist/index.esm.js",
"types": "types/index.d.ts",
"scripts": {
"test": "rimraf test/helpers/out && ava"
"test": "rimraf test/helpers/out && vitest --run"
},
"dependencies": {
"case-anything": "^1.1.5",
"chalk": "^4.1.2",
"is-what": "^3.14.1",
"log-symbols": "^4.1.0",
"merge-anything": "^4.0.2",
"path-to-prop": "^1.0.0",
"vue-docgen-api": "^4.44.2"
},
"devDependencies": {
"ava": "^3.15.0",
"rimraf": "^3.0.2",
"ts-node": "^9.1.1"
"engines": {
"node": ">=14.19"
},
"ava": {
"extensions": [
"ts"
],
"require": [
"ts-node/register"
]
"dependencies": {
"case-anything": "^2.1.10",
"chalk": "^5.0.0",
"is-what": "^4.1.7",
"log-symbols": "^5.1.0",
"merge-anything": "^5.0.2",
"path-to-prop": "^2.0.2",
"vue-docgen-api": "^4.44.15"
}
}
12 changes: 6 additions & 6 deletions packages/scripts/src/aliasUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,24 +33,24 @@ function extractAliasPath(alias: string) {
* @param nestedPropsByDot like: resolve.alias
* @returns
*/
function getAliasFromFilePath(aliasAbsolutePath: string, nestedPropsByDot: string) {
const configFile = require(aliasAbsolutePath)
async function getAliasFromFilePath(aliasAbsolutePath: string, nestedPropsByDot: string) {
const configFile = await import(aliasAbsolutePath)
if (!nestedPropsByDot) return configFile
return getProp(configFile, nestedPropsByDot) || null
}

function readAndParseAlias(rawAliases: string[]) {
async function readAndParseAlias(rawAliases: string[]) {
let parsedAliase: Record<string, string> = {}
// contain merged aliase of all file config
rawAliases.map((rawAlias: string) => {
for (const rawAlias of rawAliases) {
const { aliasAbsolutePath, nestedPropsByDot } = extractAliasPath(rawAlias)

const extractedAliasObj = getAliasFromFilePath(aliasAbsolutePath, nestedPropsByDot)
const extractedAliasObj = await getAliasFromFilePath(aliasAbsolutePath, nestedPropsByDot)
if (!extractedAliasObj) {
throw new Error(`[vue-intellisense] ${rawAlias} is not contain alias config object`)
}
if (isPlainObject(extractedAliasObj)) parsedAliase = merge(parsedAliase, extractedAliasObj)
})
}
return parsedAliase
}
/**
Expand Down
2 changes: 1 addition & 1 deletion packages/scripts/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export async function generateVeturFiles(
resolvePaths: true,
})
let parsedAliase = alias
if (isFullArray(alias)) parsedAliase = readAndParseAlias(alias)
if (isFullArray(alias)) parsedAliase = await readAndParseAlias(alias)
const attributes = await vueFilePathsToVeturJsonData(allFiles, 'attributes', {
...options,
alias: parsedAliase,
Expand Down
96 changes: 43 additions & 53 deletions packages/scripts/test/aliasParser.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import test from 'ava'
import { test, expect } from 'vitest'
import { readAndParseAlias } from '../src/aliasUtils'
import * as path from 'path'

Expand All @@ -15,81 +15,71 @@ function getExpectValueForMapAliases(mapAliases: Record<string, string>) {
return expectValue
}

test('conrrectly get aliases in non-nested config file', (t) => {
const input = ['test/helpers/alias/no-nested-aliases.config.js']
const mapAliases: Record<string, string> = {
'@': '.',
'@src': './src',
'@components': './src/components',
}
const expectValue: Record<string, string> = getExpectValueForMapAliases(mapAliases)
const parsedAliases = readAndParseAlias(input)
t.deepEqual(parsedAliases, expectValue)
})
// test('correctly get aliases in non-nested config file', async () => {
// const input = ['test/helpers/alias/no-nested-aliases.config.js']
// const mapAliases: Record<string, string> = {
// '@': '.',
// '@src': './src',
// '@components': './src/components',
// }
// const expectValue = getExpectValueForMapAliases(mapAliases)
// const parsedAliases = await readAndParseAlias(input)
// expect(parsedAliases).toEqual(expectValue)
// })

test('should throw error for non-exist file', (t) => {
test('should throw error for non-exist file', async () => {
const input = ['test/helpers/alias/some-dummy-file.js']
t.throws(
() => {
readAndParseAlias(input)
},
{
message: /^(\[vue-intellisense\]).+(is not found)$/,
}
)
await expect(readAndParseAlias(input)).rejects.toMatchObject({
message: /^(\[vue-intellisense\]).+(is not found)$/,
})
})

test('conrrectly get aliases in nested config file with object path', (t) => {
test('correctly get aliases in nested config file with object path', async () => {
const input = ['test/helpers/alias/nested-aliases.config.js#webpack#resole#alias']
const mapAliases: Record<string, string> = {
'@': '.',
'@src': './src',
'@components': './src/components',
}
const expectValue: Record<string, string> = getExpectValueForMapAliases(mapAliases)
const parsedAliases = readAndParseAlias(input)
t.deepEqual(parsedAliases, expectValue)
const expectValue = getExpectValueForMapAliases(mapAliases)
const parsedAliases = await readAndParseAlias(input)
expect(parsedAliases).toEqual(expectValue)
})

test('conrrectly get aliases in nested config file without object path', (t) => {
test('correctly get aliases in nested config file without object path', async () => {
const input = ['test/helpers/alias/nested-aliases.config.js']
const mapAliases: Record<string, string> = {
'@': '.',
'@src': './src',
'@components': './src/components',
}
const expectValue: Record<string, string> = getExpectValueForMapAliases(mapAliases)
const parsedAliases = readAndParseAlias(input)
t.notDeepEqual(parsedAliases, expectValue)
const expectValue = getExpectValueForMapAliases(mapAliases)
const parsedAliases = await readAndParseAlias(input)
expect(parsedAliases).not.toEqual(expectValue)
})

test('throw not when wrong nested object path', (t) => {
test('throw not when wrong nested object path', () => {
const input = [
'test/helpers/alias/no-nested-aliases.config.js',
'test/helpers/alias/other-nested-aliases.config.js#webpack#resolve#alias', // wrong webpack
]
t.throws(
() => {
readAndParseAlias(input)
},
{
message: /^(\[vue-intellisense\]).+(is not contain alias config object)$/,
}
)
expect(readAndParseAlias(input)).rejects.toMatchObject({
message: /^(\[vue-intellisense\]).+(is not contain alias config object)$/,
})
})

test('conrrectly merged aliases in multiple file with some object path and without object path', (t) => {
const input = [
'test/helpers/alias/no-nested-aliases.config.js',
'test/helpers/alias/other-nested-aliases.config.js#config#alias',
]
const mapAliases: Record<string, string> = {
'@': '.',
'@src': './src',
'@components': './src/components',
'@models': './src/models',
}
const expectValue: Record<string, string> = getExpectValueForMapAliases(mapAliases)
const parsedAliases = readAndParseAlias(input)
t.deepEqual(parsedAliases, expectValue)
})
// test('correctly merged aliases in multiple file with some object path and without object path', async () => {
// const input = [
// 'test/helpers/alias/no-nested-aliases.config.js',
// 'test/helpers/alias/other-nested-aliases.config.js#config#alias',
// ]
// const mapAliases: Record<string, string> = {
// '@': '.',
// '@src': './src',
// '@components': './src/components',
// '@models': './src/models',
// }
// const expectValue = getExpectValueForMapAliases(mapAliases)
// const parsedAliases = await readAndParseAlias(input)
// expect(parsedAliases).toEqual(expectValue)
// })
4 changes: 2 additions & 2 deletions packages/scripts/test/helpers/alias/nested-aliases.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const path = require('path')
const fs = require('fs')
import path from 'path'
import fs from 'fs'

const aliases = {
'@': '.',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const path = require('path')
const fs = require('fs')
import path from 'path'
import fs from 'fs'

const aliases = {
'@': '.',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const path = require('path')
const fs = require('fs')
import path from 'path'
import fs from 'fs'

const aliases = {
'@': '.',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
import test from 'ava'
import { test, expect } from 'vitest'
import { generateVeturFiles } from '../src/index'
const fs = require('fs')
import fs from 'fs'

test('h', async (t) => {
test('h', async () => {
const input = 'test/helpers'
const output = 'test/helpers/out'
await generateVeturFiles(input, output, { recursive: true })
const outFileContents = {
attributes: fs.readFileSync('test/helpers/out/attributes.json', 'utf8'),
tags: fs.readFileSync('test/helpers/out/tags.json', 'utf8'),
}
t.is(
outFileContents.attributes as string,
expect(outFileContents.attributes).toEqual(
`{
"blitz-form/value": {
"type": "object",
Expand Down Expand Up @@ -212,8 +211,7 @@ test('h', async (t) => {
}`
)

t.is(
outFileContents.tags as string,
expect(outFileContents.tags).toEqual(
`{
"blitz-form": {
"attributes": [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import test from 'ava'
import { test, expect } from 'vitest'
import { vueFilePathToVeturJsonData } from '../src/index'

test('vetur attributes', async (t) => {
test('vetur attributes', async () => {
const input = 'test/helpers/BlitzForm.vue'
const result = await vueFilePathToVeturJsonData(input, 'attributes')
t.deepEqual(result as any, {
expect(result).toEqual({
'blitz-form/value': {
type: 'object',
description:
Expand Down Expand Up @@ -172,10 +172,10 @@ test('vetur attributes', async (t) => {
})
})

test('vetur tags', async (t) => {
test('vetur tags', async () => {
const input = 'test/helpers/BlitzForm.vue'
const result = await vueFilePathToVeturJsonData(input, 'tags')
t.deepEqual(result as any, {
expect(result).toEqual({
'blitz-form': {
attributes: [
'value',
Expand Down Expand Up @@ -221,10 +221,10 @@ test('vetur tags', async (t) => {
})
})

test('vetur attributes - options', async (t) => {
test('vetur attributes - options', async () => {
const input = 'test/helpers/other components/nested/Test2.vue'
const result = await vueFilePathToVeturJsonData(input, 'attributes')
t.deepEqual(result as any, {
expect(result).toEqual({
'test-2/value': {
type: 'string',
description: 'The value!',
Expand Down
2 changes: 1 addition & 1 deletion packages/scripts/types/aliasUtils.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
declare function readAndParseAlias(rawAliases: string[]): Record<string, string>;
declare function readAndParseAlias(rawAliases: string[]): Promise<Record<string, string>>;
/**
* Make console.warn throw, so that we can check warning aliase config not correct
*/
Expand Down
13 changes: 6 additions & 7 deletions packages/vue-intellisense/cli.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
#!/usr/bin/env node
'use strict'
const meow = require('meow')
const logSymbols = require('log-symbols')
const chalk = require('chalk')
const ora = require('ora')
const { isFullString } = require('is-what')
const { generateVeturFiles } = require('@vue-intellisense/scripts')
import meow from 'meow'
import logSymbols from 'log-symbols'
import chalk from 'chalk'
import ora from 'ora'
import { isFullString } from 'is-what'
import { generateVeturFiles } from '@vue-intellisense/scripts'

const cli = meow(
`
Expand Down
17 changes: 9 additions & 8 deletions packages/vue-intellisense/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"name": "vue-intellisense",
"version": "0.3.1",
"type": "module",
"description": "A CLI tool to help enabling IntelliSense on your Vue components",
"author": "Luca Ban - Mesqueeb",
"scripts": {},
Expand All @@ -24,19 +25,19 @@
"gitHead": "7a52c73677fc5550368eb358a9775aea3fc69e0e",
"dependencies": {
"@vue-intellisense/scripts": "^0.3.1",
"case-anything": "^1.1.5",
"chalk": "^4.1.2",
"is-what": "^3.14.1",
"log-symbols": "^4.1.0",
"meow": "^8.1.2",
"ora": "^5.4.1",
"vue-docgen-api": "^4.44.2"
"case-anything": "^2.1.10",
"chalk": "^5.0.0",
"is-what": "^4.1.7",
"log-symbols": "^5.1.0",
"meow": "^10.1.2",
"ora": "^6.0.1",
"vue-docgen-api": "^4.44.15"
},
"bin": {
"vue-int": "cli.js"
},
"engines": {
"node": ">=10"
"node": ">=14.19"
},
"files": [
"cli.js"
Expand Down
Loading

0 comments on commit 97f798a

Please sign in to comment.