vue3-sfc-loader
Advanced tools
Comparing version 0.2.11 to 0.2.12
### [0.2.12](https://github.com/FranckFreiburger/vue3-sfc-loader/compare/v0.2.11...v0.2.12) (2020-11-29) | ||
### Features | ||
* **core:** add code-frame in compilation errors for template, style, SFC script ad imported scripts ([521bea6](https://github.com/FranckFreiburger/vue3-sfc-loader/commit/521bea6f33f75b256ce2e8c28b0e21c4d023c887)) | ||
### [0.2.11](https://github.com/FranckFreiburger/vue3-sfc-loader/compare/v0.2.10...v0.2.11) (2020-11-28) | ||
@@ -3,0 +10,0 @@ |
@@ -131,3 +131,3 @@ interface Cache { | ||
/** | ||
* Called by the library when it does not handle a loaded file type (eg. .json files). | ||
* Used by the library when it does not know how to handle a given file type (eg. `.json` files). | ||
* see [[additionalModuleHandlers]] | ||
@@ -138,2 +138,4 @@ * @param source The content of the file | ||
* | ||
* **example:** | ||
* | ||
* ```javascript | ||
@@ -140,0 +142,0 @@ * ... |
@@ -24,3 +24,3 @@ **[vue3-sfc-loader](../README.md)** | ||
*Defined in [index.ts:67](https://github.com/FranckFreiburger/vue3-sfc-loader/blob/af93193/src/index.ts#L67)* | ||
*Defined in [index.ts:67](https://github.com/FranckFreiburger/vue3-sfc-loader/blob/b21af67/src/index.ts#L67)* | ||
@@ -41,3 +41,3 @@ #### Parameters: | ||
*Defined in [index.ts:68](https://github.com/FranckFreiburger/vue3-sfc-loader/blob/af93193/src/index.ts#L68)* | ||
*Defined in [index.ts:68](https://github.com/FranckFreiburger/vue3-sfc-loader/blob/b21af67/src/index.ts#L68)* | ||
@@ -44,0 +44,0 @@ #### Parameters: |
@@ -7,3 +7,3 @@ **[vue3-sfc-loader](../README.md)** | ||
Called by the library when it does not handle a loaded file type (eg. .json files). | ||
Used by the library when it does not know how to handle a given file type (eg. `.json` files). | ||
see [additionalModuleHandlers](options.md#additionalmodulehandlers) | ||
@@ -19,5 +19,5 @@ | ||
*Defined in [index.ts:231](https://github.com/FranckFreiburger/vue3-sfc-loader/blob/af93193/src/index.ts#L231)* | ||
*Defined in [index.ts:233](https://github.com/FranckFreiburger/vue3-sfc-loader/blob/b21af67/src/index.ts#L233)* | ||
Called by the library when it does not handle a loaded file type (eg. .json files). | ||
Used by the library when it does not know how to handle a given file type (eg. `.json` files). | ||
see [additionalModuleHandlers](options.md#additionalmodulehandlers) | ||
@@ -31,4 +31,4 @@ | ||
`path` | string | The path of the file | | ||
`options` | [Options](options.md) | The options ```javascript ... additionalModuleHandlers: { '.json': (source, path, options) => JSON.parse(source), } ... ``` | | ||
`options` | [Options](options.md) | The options **example:** ```javascript ... additionalModuleHandlers: { '.json': (source, path, options) => JSON.parse(source), } ... ``` | | ||
**Returns:** Promise\<[Module](module.md)> |
@@ -32,3 +32,3 @@ **[vue3-sfc-loader](../README.md)** | ||
*Defined in [index.ts:140](https://github.com/FranckFreiburger/vue3-sfc-loader/blob/af93193/src/index.ts#L140)* | ||
*Defined in [index.ts:140](https://github.com/FranckFreiburger/vue3-sfc-loader/blob/b21af67/src/index.ts#L140)* | ||
@@ -48,3 +48,3 @@ Additional babel plugins. [TBD] | ||
*Defined in [index.ts:147](https://github.com/FranckFreiburger/vue3-sfc-loader/blob/af93193/src/index.ts#L147)* | ||
*Defined in [index.ts:147](https://github.com/FranckFreiburger/vue3-sfc-loader/blob/b21af67/src/index.ts#L147)* | ||
@@ -59,3 +59,3 @@ Additional module type handlers. see [ModuleHandler](modulehandler.md) | ||
*Defined in [index.ts:186](https://github.com/FranckFreiburger/vue3-sfc-loader/blob/af93193/src/index.ts#L186)* | ||
*Defined in [index.ts:186](https://github.com/FranckFreiburger/vue3-sfc-loader/blob/b21af67/src/index.ts#L186)* | ||
@@ -103,3 +103,3 @@ [get](cache.md#get)() and [set](cache.md#set)() functions of this object are called when the lib needs to save or load already compiled code. get and set functions must return a `Promise` (or can be `async`). | ||
*Defined in [index.ts:89](https://github.com/FranckFreiburger/vue3-sfc-loader/blob/af93193/src/index.ts#L89)* | ||
*Defined in [index.ts:89](https://github.com/FranckFreiburger/vue3-sfc-loader/blob/b21af67/src/index.ts#L89)* | ||
@@ -124,3 +124,3 @@ Initial cache that will contain resolved dependencies. | ||
*Defined in [index.ts:129](https://github.com/FranckFreiburger/vue3-sfc-loader/blob/af93193/src/index.ts#L129)* | ||
*Defined in [index.ts:129](https://github.com/FranckFreiburger/vue3-sfc-loader/blob/b21af67/src/index.ts#L129)* | ||
@@ -157,3 +157,3 @@ Called by the library when CSS style must be added in the HTML document. | ||
*Defined in [index.ts:107](https://github.com/FranckFreiburger/vue3-sfc-loader/blob/af93193/src/index.ts#L107)* | ||
*Defined in [index.ts:107](https://github.com/FranckFreiburger/vue3-sfc-loader/blob/b21af67/src/index.ts#L107)* | ||
@@ -188,3 +188,3 @@ Called by the library when it needs a file. | ||
*Defined in [index.ts:204](https://github.com/FranckFreiburger/vue3-sfc-loader/blob/af93193/src/index.ts#L204)* | ||
*Defined in [index.ts:204](https://github.com/FranckFreiburger/vue3-sfc-loader/blob/b21af67/src/index.ts#L204)* | ||
@@ -191,0 +191,0 @@ Called by the library when there is somthing to log (eg. scripts compilation errors, template compilation errors, template compilation tips, style compilation errors, ...) |
@@ -30,3 +30,3 @@ **[vue3-sfc-loader](README.md)** | ||
*Defined in [index.ts:248](https://github.com/FranckFreiburger/vue3-sfc-loader/blob/af93193/src/index.ts#L248)* | ||
*Defined in [index.ts:250](https://github.com/FranckFreiburger/vue3-sfc-loader/blob/b21af67/src/index.ts#L250)* | ||
@@ -41,3 +41,3 @@ the version of the library (process.env.VERSION is set by webpack, at compile-time) | ||
*Defined in [index.ts:708](https://github.com/FranckFreiburger/vue3-sfc-loader/blob/af93193/src/index.ts#L708)* | ||
*Defined in [index.ts:727](https://github.com/FranckFreiburger/vue3-sfc-loader/blob/b21af67/src/index.ts#L727)* | ||
@@ -44,0 +44,0 @@ This is the main function. |
@@ -11,3 +11,3 @@ { | ||
"license": "MIT", | ||
"version": "0.2.11", | ||
"version": "0.2.12", | ||
"main": "dist/vue3-sfc-loader.js", | ||
@@ -14,0 +14,0 @@ "scripts": { |
@@ -16,3 +16,3 @@ # vue3-sfc-loader | ||
<script src="https://unpkg.com/vue@next"></script> | ||
<script src="https://cdn.jsdelivr.net/npm/vue3-sfc-loader/dist/vue3-sfc-loader.js"></script> | ||
<script src="https://cdn.jsdelivr.net/npm/vue3-sfc-loader"></script> | ||
<script> | ||
@@ -66,4 +66,4 @@ | ||
latest minified version: | ||
- at jsDelivr CDN: https://cdn.jsdelivr.net/npm/vue3-sfc-loader/dist/vue3-sfc-loader.js | ||
- at UNPKG CDN: https://unpkg.com/vue3-sfc-loader/dist/vue3-sfc-loader.js | ||
- at jsDelivr CDN: https://cdn.jsdelivr.net/npm/vue3-sfc-loader | ||
- at UNPKG CDN: https://unpkg.com/vue3-sfc-loader | ||
@@ -94,3 +94,3 @@ ### Bundle size | ||
`Webpack`( `@vue/compiler-sfc` + `@babel` ) = `vue3-sfc-loader.js` | ||
`vue3-sfc-loader.js` = `Webpack`( `@vue/compiler-sfc` + `@babel` ) | ||
@@ -123,3 +123,3 @@ | ||
<script src="https://unpkg.com/vue@next"></script> | ||
<script src="https://cdn.jsdelivr.net/npm/vue3-sfc-loader/dist/vue3-sfc-loader.js"></script> | ||
<script src="https://cdn.jsdelivr.net/npm/vue3-sfc-loader"></script> | ||
@@ -291,3 +291,3 @@ <script> | ||
<script src="https://unpkg.com/vue@next"></script> | ||
<script src="https://cdn.jsdelivr.net/npm/vue3-sfc-loader/dist/vue3-sfc-loader.js"></script> | ||
<script src="https://cdn.jsdelivr.net/npm/vue3-sfc-loader"></script> | ||
<script> | ||
@@ -294,0 +294,0 @@ const sfcSontent = /* <!-- */` |
@@ -24,3 +24,3 @@ import { posix as Path } from 'path' | ||
// @ts-ignore | ||
// @ts-ignore (Could not find a declaration file for module '@babel/plugin-transform-modules-commonjs') | ||
import babelPluginTransformModulesCommonjs from '@babel/plugin-transform-modules-commonjs' | ||
@@ -218,3 +218,3 @@ | ||
/** | ||
* Called by the library when it does not handle a loaded file type (eg. .json files). | ||
* Used by the library when it does not know how to handle a given file type (eg. `.json` files). | ||
* see [[additionalModuleHandlers]] | ||
@@ -225,2 +225,4 @@ * @param source The content of the file | ||
* | ||
* **example:** | ||
* | ||
* ```javascript | ||
@@ -273,2 +275,17 @@ * ... | ||
*/ | ||
function formatError(message : string, path : string, source : string, line : number, column : number) : string { | ||
const location = { | ||
start: { line, column }, | ||
}; | ||
return '\n' + path + '\n' + codeFrameColumns(source, location, { | ||
message, | ||
}) + '\n'; | ||
} | ||
/** | ||
* @internal | ||
*/ | ||
function hash(...valueList : any[]) : string { | ||
@@ -326,3 +343,3 @@ | ||
if ( | ||
// @ts-ignore | ||
// @ts-ignore (Property 'name' does not exist on type 'ArrayExpression') | ||
path.node.callee.name === 'require' | ||
@@ -453,10 +470,18 @@ && path.node.arguments.length === 1 | ||
const { additionalBabelPlugins = [] } = options; | ||
const { additionalBabelPlugins = [], log } = options; | ||
const ast = babel_parse(source, { | ||
// doc: https://babeljs.io/docs/en/babel-parser#options | ||
sourceType: moduleSourceType ? 'module' : 'script', | ||
sourceFilename: filename, | ||
}); | ||
let ast; | ||
try { | ||
ast = babel_parse(source, { | ||
// doc: https://babeljs.io/docs/en/babel-parser#options | ||
sourceType: moduleSourceType ? 'module' : 'script', | ||
sourceFilename: filename, | ||
}); | ||
} catch(ex) { | ||
log?.('error', 'dep script', formatError(ex.message, filename, source, ex.loc.line, ex.loc.column + 1) ); | ||
throw ex; | ||
} | ||
renameDynamicImport(ast); | ||
@@ -574,15 +599,3 @@ const depsList = parseDeps(ast); | ||
const location = { | ||
start: { | ||
line: ex.loc.line, | ||
column: ex.loc.column + 1, | ||
} | ||
}; | ||
const formatedMessage = codeFrameColumns(source, location, { | ||
message: ex.message, | ||
}); | ||
log?.('error', 'SFC script', formatedMessage); | ||
log?.('error', 'SFC script', formatError(ex.message, filename, source, ex.loc.line, ex.loc.column + 1) ); | ||
throw ex; | ||
@@ -625,4 +638,7 @@ } | ||
preventCache(); | ||
for ( const err of template.errors ) | ||
log?.('warn', 'SFC template', err); | ||
for ( const err of template.errors ) { | ||
// @ts-ignore (Property 'message' does not exist on type 'string | CompilerError') | ||
log?.('error', 'SFC template', formatError(err.message, filename, source, err.loc.start.line + descriptor.template.loc.start.line - 1, err.loc.start.column) ); | ||
} | ||
} | ||
@@ -640,5 +656,5 @@ | ||
for ( const e of descriptor.styles ) { | ||
for ( const descStyle of descriptor.styles ) { | ||
const style = await withCache(compiledCache, [ componentHash, e.content ], async ({ preventCache }) => { | ||
const style = await withCache(compiledCache, [ componentHash, descStyle.content ], async ({ preventCache }) => { | ||
@@ -648,8 +664,8 @@ // src: https://github.com/vuejs/vue-next/blob/15baaf14f025f6b1d46174c9713a2ec517741d0d/packages/compiler-sfc/src/compileStyle.ts#L70 | ||
filename: descriptor.filename, | ||
source: e.content, | ||
source: descStyle.content, | ||
isProd, | ||
id: scopeId, | ||
scoped: e.scoped, | ||
scoped: descStyle.scoped, | ||
trim: true, | ||
preprocessLang: e.lang as PreprocessLang, | ||
preprocessLang: descStyle.lang as PreprocessLang, | ||
preprocessCustomRequire: id => moduleCache[id], | ||
@@ -661,4 +677,7 @@ }); | ||
preventCache(); | ||
for ( const err of compiledStyle.errors ) | ||
log?.('warn', 'SFC style', err); | ||
for ( const err of compiledStyle.errors ) { | ||
// @ts-ignore (Property 'line' does not exist on type 'Error' and Property 'column' does not exist on type 'Error') | ||
log?.('error', 'SFC style', formatError(err.message, filename, source, err.line + descStyle.loc.start.line - 1, err.column) ); | ||
} | ||
} | ||
@@ -665,0 +684,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
7638
3988343
23