chore: update oxc-walker + improve tests

This commit is contained in:
Daniel Roe 2024-12-09 16:20:36 +00:00
parent 84680265f2
commit 007922f27c
No known key found for this signature in database
GPG Key ID: 3714AB03996F442B
4 changed files with 90 additions and 73 deletions

View File

@ -106,8 +106,8 @@
"nypm": "^0.4.1", "nypm": "^0.4.1",
"ofetch": "^1.4.1", "ofetch": "^1.4.1",
"ohash": "^1.1.4", "ohash": "^1.1.4",
"oxc-parser": "^0.38.0", "oxc-parser": "^0.39.0",
"oxc-walker": "^0.0.1", "oxc-walker": "^0.1.2",
"pathe": "^1.1.2", "pathe": "^1.1.2",
"perfect-debounce": "^1.0.0", "perfect-debounce": "^1.0.0",
"pkg-types": "^1.2.1", "pkg-types": "^1.2.1",

View File

@ -4,29 +4,26 @@ import { RemovePluginMetadataPlugin, extractMetadata } from '../src/core/plugins
import { checkForCircularDependencies } from '../src/core/app' import { checkForCircularDependencies } from '../src/core/app'
describe('plugin-metadata', () => { describe('plugin-metadata', () => {
it('should extract metadata from object-syntax plugins', async () => { const properties = Object.entries({
const properties = Object.entries({ name: 'test',
name: 'test', enforce: 'post',
enforce: 'post', hooks: { 'app:mounted': () => {} },
hooks: { 'app:mounted': () => {} }, setup: () => { return { provide: { jsx: '[JSX]' } } },
setup: () => { return { provide: { jsx: '[JSX]' } } }, order: 1,
order: 1, })
it.each(properties)('should extract metadata from object-syntax plugins', async (k, value) => {
const obj = [...properties.filter(([key]) => key !== k), [k, value]]
const meta = await extractMetadata([
'export default defineNuxtPlugin({',
...obj.map(([key, value]) => `${key}: ${typeof value === 'function' ? value.toString().replace('"[JSX]"', '() => <span>JSX</span>') : JSON.stringify(value)},`),
'})',
].join('\n'), 'file.tsx')
expect(meta).toEqual({
'name': 'test',
'order': 1,
}) })
for (const item of properties) {
const obj = [...properties.filter(([key]) => key !== item[0]), item]
const meta = await extractMetadata([
'export default defineNuxtPlugin({',
...obj.map(([key, value]) => `${key}: ${typeof value === 'function' ? value.toString().replace('"[JSX]"', '() => <span>JSX</span>') : JSON.stringify(value)},`),
'})',
].join('\n'), 'file.tsx')
expect(meta).toEqual({
'name': 'test',
'order': 1,
})
}
}) })
const transformPlugin: any = RemovePluginMetadataPlugin({ const transformPlugin: any = RemovePluginMetadataPlugin({

View File

@ -55,7 +55,7 @@ const treeshakeTemplatePlugin = TreeShakeTemplatePlugin({
const treeshake = async (source: string): Promise<string> => { const treeshake = async (source: string): Promise<string> => {
// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type // eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
const result = await (treeshakeTemplatePlugin.transform! as Function)(source) const result = await (treeshakeTemplatePlugin.transform! as Function)(source, 'test.ts')
return typeof result === 'string' ? result : result?.code return typeof result === 'string' ? result : result?.code
} }

View File

@ -394,11 +394,11 @@ importers:
specifier: 1.1.4 specifier: 1.1.4
version: 1.1.4 version: 1.1.4
oxc-parser: oxc-parser:
specifier: ^0.38.0 specifier: ^0.39.0
version: 0.38.0 version: 0.39.0
oxc-walker: oxc-walker:
specifier: ^0.0.1 specifier: ^0.1.0
version: 0.0.1 version: 0.1.0(oxc-parser@0.39.0)
pathe: pathe:
specifier: ^1.1.2 specifier: ^1.1.2
version: 1.1.2 version: 1.1.2
@ -2093,48 +2093,48 @@ packages:
'@one-ini/wasm@0.1.1': '@one-ini/wasm@0.1.1':
resolution: {integrity: sha512-XuySG1E38YScSJoMlqovLru4KTUNSjgVTIjyh7qMX6aNN5HY5Ct5LhRJdxO79JtTzKfzV/bnWpz+zquYrISsvw==} resolution: {integrity: sha512-XuySG1E38YScSJoMlqovLru4KTUNSjgVTIjyh7qMX6aNN5HY5Ct5LhRJdxO79JtTzKfzV/bnWpz+zquYrISsvw==}
'@oxc-parser/binding-darwin-arm64@0.38.0': '@oxc-parser/binding-darwin-arm64@0.39.0':
resolution: {integrity: sha512-yMDY/KrF2gEEpVIzaVWuO1savy303onvhg96a+1mUfLhgH9lvfZZyus4/LVokRHYCCy+6ey/1ytyilVnSeTDYA==} resolution: {integrity: sha512-IP7USw9mHYTyfT/nwQZvdS/Z1TqfzV6j6EtK60t5jfvl1CeSXOUyZzO9WFdW2c0F+DgcSjR9hJkwpCwJzzBjXw==}
cpu: [arm64] cpu: [arm64]
os: [darwin] os: [darwin]
'@oxc-parser/binding-darwin-x64@0.38.0': '@oxc-parser/binding-darwin-x64@0.39.0':
resolution: {integrity: sha512-OD8PQT5nAdNCbmzMVfafIQi9/yxSvfEH5fpLXPKVTCtAEc/d5aX6JpipjW231/3TF8mjXO1y3xZM1xKGXJEk/A==} resolution: {integrity: sha512-0hZvJX5F6HIlLDs1VfVBHVHaY98tGmNpCr1eOcbz5A5rrtE/AF5c6Rf23jE763a+vQKTMyHmohjEsqw+jlXZfw==}
cpu: [x64] cpu: [x64]
os: [darwin] os: [darwin]
'@oxc-parser/binding-linux-arm64-gnu@0.38.0': '@oxc-parser/binding-linux-arm64-gnu@0.39.0':
resolution: {integrity: sha512-REfFdTk+cdIC8etE8v0CoZtVObKIiymFsPkQTYca2V2ZwJ9/SgUr6NNNjLJdkGOipwjBk8d2cyOZzNDIMfzmqw==} resolution: {integrity: sha512-sECHgo55REvlL+sU1ITG7uXuERd1cZIlQbFf0E0Eqq47a3gMS9CUcsdc3OmRYTA6p7W45agktw/tRrHpJDBhNg==}
cpu: [arm64] cpu: [arm64]
os: [linux] os: [linux]
'@oxc-parser/binding-linux-arm64-musl@0.38.0': '@oxc-parser/binding-linux-arm64-musl@0.39.0':
resolution: {integrity: sha512-tSDRTahOoT4KDS0dicDEFgBH2nEDqNmqFG+N6PS2LrExYEDS01noRIxMFpx2Sz22a+6ZnvkfVmStp6VK+9fpBQ==} resolution: {integrity: sha512-YzLPmO8UYkTKSW7yDZB53S5HfM2SWKaqLSV7KcTdOZgash5Qd38QwyiE4T2aOzEBRiybpXZYapjBqFDvDfR1Lg==}
cpu: [arm64] cpu: [arm64]
os: [linux] os: [linux]
'@oxc-parser/binding-linux-x64-gnu@0.38.0': '@oxc-parser/binding-linux-x64-gnu@0.39.0':
resolution: {integrity: sha512-qc6NdCzcCAxCK5KVde2ULq+7cyiJwrMV/1yozSUqvu26yme56Es3rWHFuPToxrhw+2olvc93AX+PVYMy3DqrGw==} resolution: {integrity: sha512-h4F6M9H4gjRIjcMPbP+TItGjIIjbOFI22rOpX/FHM5VpiOrVun6nKlmu8Lub1Qzy6cI/2JAQlV17ETdjMmuDpA==}
cpu: [x64] cpu: [x64]
os: [linux] os: [linux]
'@oxc-parser/binding-linux-x64-musl@0.38.0': '@oxc-parser/binding-linux-x64-musl@0.39.0':
resolution: {integrity: sha512-x/9XyivlMjnQ7gofNK6u+L+BMdwKf/GuLJ0vrmrWolKGR9CBSzZRwZfTw+cG0T7U6Y6CN36tSqijA0eTo3U8zw==} resolution: {integrity: sha512-7krHX7FfNTAJygFIUJa3xSmSfTpmb+E8rOUeqkE3jeFM2D1As7y5adoWi3vuHY3UMDy6w3Q1Umcyylxqzp4ujA==}
cpu: [x64] cpu: [x64]
os: [linux] os: [linux]
'@oxc-parser/binding-win32-arm64-msvc@0.38.0': '@oxc-parser/binding-win32-arm64-msvc@0.39.0':
resolution: {integrity: sha512-SUlt+MUid0VUL5cLbbZzVGA9xNoqLl29xF1ueTeDt/BdQyrLELjTxoGtgisF6blAD6Rj2JqPtnfk+CT7GBwL2w==} resolution: {integrity: sha512-4Puf8gojVwG3nIGyi1B8oVl89dit+kcd3eTH8x9exz+KoihstJbWbyAkezB9W5K86FcZE8dbVcHWDifF6sSu/Q==}
cpu: [arm64] cpu: [arm64]
os: [win32] os: [win32]
'@oxc-parser/binding-win32-x64-msvc@0.38.0': '@oxc-parser/binding-win32-x64-msvc@0.39.0':
resolution: {integrity: sha512-l/nFJutJ+zZTGj7ayL22r+og8g6dOC/47fSlsyl+KQXsmAFDStaARioHP9g+von/0bS23LX/9Eo8YeK5kFc7KA==} resolution: {integrity: sha512-Qy5kvBUtscM2VJ0q/Y7N9546HiL/JrV1MvMf+Q4ORrApO3JfMSyoJdIaFz6SxytiQLRtOFnkjfACCl4qcvYRQg==}
cpu: [x64] cpu: [x64]
os: [win32] os: [win32]
'@oxc-project/types@0.38.0': '@oxc-project/types@0.39.0':
resolution: {integrity: sha512-WjRra3cmQt/VPRTwiVuYITm6RNr4SjwYeVZkT0oPn1M0Li2caILj1mlRELhHXad4nLAlnfliH5daHFKjQ9d3jQ==} resolution: {integrity: sha512-S70sRLmlZA3NIQXp3gkBKOkFFpIaNtpLtSFp3Tejre2HsUthJ9dVTTGvJhkZOlIdJs8LGFZ5HTX4jLNcC2RxFg==}
'@parcel/watcher-android-arm64@2.5.0': '@parcel/watcher-android-arm64@2.5.0':
resolution: {integrity: sha512-qlX4eS28bUcQCdribHkg/herLe+0A9RyYC+mm2PXpncit8z5b3nSqGVzMNR3CmtAOgRutiZ02eIJJgP/b1iEFQ==} resolution: {integrity: sha512-qlX4eS28bUcQCdribHkg/herLe+0A9RyYC+mm2PXpncit8z5b3nSqGVzMNR3CmtAOgRutiZ02eIJJgP/b1iEFQ==}
@ -5400,6 +5400,9 @@ packages:
resolution: {integrity: sha512-h5bgJWpxJNswbU7qCrV0tIKQCaS3blPDrqKWx+QxzuzL1zGUzij9XCWLrSLsJPu5t+eWA/ycetzYAO5IOMcWAQ==} resolution: {integrity: sha512-h5bgJWpxJNswbU7qCrV0tIKQCaS3blPDrqKWx+QxzuzL1zGUzij9XCWLrSLsJPu5t+eWA/ycetzYAO5IOMcWAQ==}
hasBin: true hasBin: true
magic-regexp@0.8.0:
resolution: {integrity: sha512-lOSLWdE156csDYwCTIGiAymOLN7Epu/TU5e/oAnISZfU6qP+pgjkE+xbVjVn3yLPKN8n1G2yIAYTAM5KRk6/ow==}
magic-string-ast@0.6.2: magic-string-ast@0.6.2:
resolution: {integrity: sha512-oN3Bcd7ZVt+0VGEs7402qR/tjgjbM7kPlH/z7ufJnzTLVBzXJITRHOJiwMmmYMgZfdoWQsfQcY+iKlxiBppnMA==} resolution: {integrity: sha512-oN3Bcd7ZVt+0VGEs7402qR/tjgjbM7kPlH/z7ufJnzTLVBzXJITRHOJiwMmmYMgZfdoWQsfQcY+iKlxiBppnMA==}
engines: {node: '>=16.14.0'} engines: {node: '>=16.14.0'}
@ -5925,11 +5928,13 @@ packages:
resolution: {integrity: sha512-6IpQ7mKUxRcZNLIObR0hz7lxsapSSIYNZJwXPGeF0mTVqGKFIXj1DQcMoT22S3ROcLyY/rz0PWaWZ9ayWmad9g==} resolution: {integrity: sha512-6IpQ7mKUxRcZNLIObR0hz7lxsapSSIYNZJwXPGeF0mTVqGKFIXj1DQcMoT22S3ROcLyY/rz0PWaWZ9ayWmad9g==}
engines: {node: '>= 0.8.0'} engines: {node: '>= 0.8.0'}
oxc-parser@0.38.0: oxc-parser@0.39.0:
resolution: {integrity: sha512-w/cUL64wDb72gaBoOnvodKgHhNF9pDjb2b8gPkDKJDTvIvlbcE9XGDT3cnXOP4N3XCMrRT4MC23bCHGb3gCFSQ==} resolution: {integrity: sha512-MnSAlAFyUvUMBEWna6y4wSu5lZzl1wcnvQul54uXaHinUlRjAeBd6wOAQqLKeNXRseVsXO9/2ALi327favfVkw==}
oxc-walker@0.0.1: oxc-walker@0.1.0:
resolution: {integrity: sha512-lb1iCUTl2qy/ZYk1+lC8nxUBzCpcsupofSFqwHlP3GtbE/2uLq2A0Q448fDs9LDIuh+syC6sebonI0qpjh2Opw==} resolution: {integrity: sha512-cUmfE8i8HglpkA/0TgqbMVl8VWwO1lpsOW57suFS/I0zM9TITwDX/VkndqWe2B9LGcTYgmUrh3G+5ThMizbA3A==}
peerDependencies:
oxc-parser: ^0.38.0 || ^0.39.0
p-limit@2.3.0: p-limit@2.3.0:
resolution: {integrity: sha512-//88mFWSJx8lxCzwdAABTJL2MyWB12+eIY7MDL2SqLmAkeKU9qxRvWuSyTjm3FUmpBEMuFfckAIqEaVGUDxb6w==} resolution: {integrity: sha512-//88mFWSJx8lxCzwdAABTJL2MyWB12+eIY7MDL2SqLmAkeKU9qxRvWuSyTjm3FUmpBEMuFfckAIqEaVGUDxb6w==}
@ -7207,6 +7212,9 @@ packages:
resolution: {integrity: sha512-yOGpmOAL7CkKe/91I5O3gPICmJNLJ1G4zFYVAsRHg7M64biSnPtRj0WNQt++bRkjYOqjWXrhnUw1utzmVErAdg==} resolution: {integrity: sha512-yOGpmOAL7CkKe/91I5O3gPICmJNLJ1G4zFYVAsRHg7M64biSnPtRj0WNQt++bRkjYOqjWXrhnUw1utzmVErAdg==}
engines: {node: '>=16'} engines: {node: '>=16'}
type-level-regexp@0.1.17:
resolution: {integrity: sha512-wTk4DH3cxwk196uGLK/E9pE45aLfeKJacKmcEgEOA/q5dnPGNxXt0cfYdFxb57L+sEpf1oJH4Dnx/pnRcku9jg==}
typescript@5.6.3: typescript@5.6.3:
resolution: {integrity: sha512-hjcS1mhfuyi4WW8IWtjP7brDrG2cuDZukyrYrSauoXGNgx0S7zceP07adYkJycEr56BOUTNPzbInooiN3fn1qw==} resolution: {integrity: sha512-hjcS1mhfuyi4WW8IWtjP7brDrG2cuDZukyrYrSauoXGNgx0S7zceP07adYkJycEr56BOUTNPzbInooiN3fn1qw==}
engines: {node: '>=14.17'} engines: {node: '>=14.17'}
@ -8989,31 +8997,31 @@ snapshots:
'@one-ini/wasm@0.1.1': {} '@one-ini/wasm@0.1.1': {}
'@oxc-parser/binding-darwin-arm64@0.38.0': '@oxc-parser/binding-darwin-arm64@0.39.0':
optional: true optional: true
'@oxc-parser/binding-darwin-x64@0.38.0': '@oxc-parser/binding-darwin-x64@0.39.0':
optional: true optional: true
'@oxc-parser/binding-linux-arm64-gnu@0.38.0': '@oxc-parser/binding-linux-arm64-gnu@0.39.0':
optional: true optional: true
'@oxc-parser/binding-linux-arm64-musl@0.38.0': '@oxc-parser/binding-linux-arm64-musl@0.39.0':
optional: true optional: true
'@oxc-parser/binding-linux-x64-gnu@0.38.0': '@oxc-parser/binding-linux-x64-gnu@0.39.0':
optional: true optional: true
'@oxc-parser/binding-linux-x64-musl@0.38.0': '@oxc-parser/binding-linux-x64-musl@0.39.0':
optional: true optional: true
'@oxc-parser/binding-win32-arm64-msvc@0.38.0': '@oxc-parser/binding-win32-arm64-msvc@0.39.0':
optional: true optional: true
'@oxc-parser/binding-win32-x64-msvc@0.38.0': '@oxc-parser/binding-win32-x64-msvc@0.39.0':
optional: true optional: true
'@oxc-project/types@0.38.0': {} '@oxc-project/types@0.39.0': {}
'@parcel/watcher-android-arm64@2.5.0': '@parcel/watcher-android-arm64@2.5.0':
optional: true optional: true
@ -12815,6 +12823,16 @@ snapshots:
lz-string@1.5.0: {} lz-string@1.5.0: {}
magic-regexp@0.8.0:
dependencies:
estree-walker: 3.0.3
magic-string: 0.30.14
mlly: 1.7.3
regexp-tree: 0.1.27
type-level-regexp: 0.1.17
ufo: 1.5.4
unplugin: 1.16.0
magic-string-ast@0.6.2: magic-string-ast@0.6.2:
dependencies: dependencies:
magic-string: 0.30.14 magic-string: 0.30.14
@ -13625,24 +13643,24 @@ snapshots:
type-check: 0.4.0 type-check: 0.4.0
word-wrap: 1.2.5 word-wrap: 1.2.5
oxc-parser@0.38.0: oxc-parser@0.39.0:
dependencies: dependencies:
'@oxc-project/types': 0.38.0 '@oxc-project/types': 0.39.0
optionalDependencies: optionalDependencies:
'@oxc-parser/binding-darwin-arm64': 0.38.0 '@oxc-parser/binding-darwin-arm64': 0.39.0
'@oxc-parser/binding-darwin-x64': 0.38.0 '@oxc-parser/binding-darwin-x64': 0.39.0
'@oxc-parser/binding-linux-arm64-gnu': 0.38.0 '@oxc-parser/binding-linux-arm64-gnu': 0.39.0
'@oxc-parser/binding-linux-arm64-musl': 0.38.0 '@oxc-parser/binding-linux-arm64-musl': 0.39.0
'@oxc-parser/binding-linux-x64-gnu': 0.38.0 '@oxc-parser/binding-linux-x64-gnu': 0.39.0
'@oxc-parser/binding-linux-x64-musl': 0.38.0 '@oxc-parser/binding-linux-x64-musl': 0.39.0
'@oxc-parser/binding-win32-arm64-msvc': 0.38.0 '@oxc-parser/binding-win32-arm64-msvc': 0.39.0
'@oxc-parser/binding-win32-x64-msvc': 0.38.0 '@oxc-parser/binding-win32-x64-msvc': 0.39.0
oxc-walker@0.0.1: oxc-walker@0.1.0(oxc-parser@0.39.0):
dependencies: dependencies:
'@types/estree': 1.0.6
estree-walker: 3.0.3 estree-walker: 3.0.3
oxc-parser: 0.38.0 magic-regexp: 0.8.0
oxc-parser: 0.39.0
p-limit@2.3.0: p-limit@2.3.0:
dependencies: dependencies:
@ -15004,6 +15022,8 @@ snapshots:
type-fest@4.26.1: {} type-fest@4.26.1: {}
type-level-regexp@0.1.17: {}
typescript@5.6.3: {} typescript@5.6.3: {}
uc.micro@2.1.0: {} uc.micro@2.1.0: {}