-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from sebamarynissen/feature/script-setup
Fix `<script setup>` in Vue 2.7
- Loading branch information
Showing
8 changed files
with
144 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,6 @@ | ||
name: CI | ||
|
||
on: | ||
push: | ||
pull_request: | ||
on: pull_request | ||
|
||
jobs: | ||
test-node: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
name: Publish | ||
|
||
on: | ||
release: | ||
types: [created] | ||
|
||
jobs: | ||
publish-npm: | ||
name: Publish to npm | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: actions/setup-node@v3 | ||
with: | ||
node-version: 18 | ||
registry-url: https://registry.npmjs.org/ | ||
cache: npm | ||
- run: npm install -g npm@latest | ||
- run: npm i | ||
- run: npm test | ||
- run: npm version ${TAG_NAME} --git-tag-version=false | ||
env: | ||
TAG_NAME: ${{ github.event.release.tag_name }} | ||
- run: npm whoami; npm --ignore-scripts publish --provenance --access public | ||
env: | ||
NODE_AUTH_TOKEN: ${{secrets.npm_token}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// # descriptor-cache.js | ||
import fs from 'node:fs'; | ||
import { resolveCompiler } from './compiler.js'; | ||
import vueVersion from './vue-version.js'; | ||
|
||
const cache = new Map(); | ||
|
||
// # getDescriptor(filename, opts) | ||
// The descriptor cache is something we need to get <script setup> working | ||
// properly. The problem is that the bindings from script setup need to be | ||
// injected in the template, but that means we need to be able to load the | ||
// descriptor again **from within the template**. Hence we abstract away getting | ||
// the descriptor and cache them by filename. | ||
export function getDescriptor(filename, opts = {}) { | ||
|
||
// Check the cache first. | ||
if (cache.has(filename)) { | ||
return cache.get(filename); | ||
} | ||
|
||
// If the source is somehow not known, it might be because loaders are | ||
// running in different threads. Not sure if node does this, but let's be | ||
// sure. | ||
const { | ||
source = fs.readFileSync(filename), | ||
version = vueVersion, | ||
} = opts; | ||
|
||
// Create the descriptor based on the version. | ||
if (version === 2) { | ||
const { sourceRoot } = opts; | ||
const { compiler, templateCompiler } = resolveCompiler(); | ||
let descriptor = compiler.parse({ | ||
source, | ||
filename, | ||
sourceRoot, | ||
...templateCompiler && { compiler: templateCompiler() }, | ||
}); | ||
cache.set(filename, descriptor); | ||
return descriptor; | ||
} | ||
|
||
// Vue 3 by default. | ||
const { compiler } = resolveCompiler(); | ||
let { descriptor } = compiler.parse(source, { filename }); | ||
cache.set(filename, descriptor); | ||
return descriptor; | ||
|
||
} | ||
|
||
// # setDescriptor(filename, descriptor) | ||
export function setDescriptor(filename, descriptor) { | ||
cache.set(filename, descriptor); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<template> | ||
<p>Hello</p> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters