Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

svelte-loader

Package Overview
Dependencies
Maintainers
2
Versions
52
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

svelte-loader - npm Package Compare versions

Comparing version 2.12.0 to 2.13.1

8

CHANGELOG.md
# svelte-loader changelog
## 2.13.1
* v3 fixes ([#78](https://github.com/sveltejs/svelte-loader/pull/78))
## 2.13.0
* Handle `dependencies` returned from `preprocess` ([#75](https://github.com/sveltejs/svelte-loader/pull/75))
## 2.12.0

@@ -4,0 +12,0 @@

66

index.js
const { basename, extname, relative } = require('path');
const { getOptions } = require('loader-utils');
const VirtualModules = require('./lib/virtual');
const requireRelative = require('require-relative');

@@ -14,2 +13,16 @@ const hotApi = require.resolve('./lib/hot-api.js');

const pluginOptions = {
externalDependencies: true,
hotReload: true,
hotOptions: true,
preprocess: true,
emitCss: true,
// legacy
shared: true,
style: true,
script: true,
markup: true
};
function makeHot(id, code, hotOptions) {

@@ -66,3 +79,3 @@ const options = JSON.stringify(hotOptions);

return { js, css, ast: compiled.ast };
return { js, css, ast: compiled.ast, warnings: compiled.warnings || compiled.stats.warnings || [] };
}

@@ -104,25 +117,44 @@

options.filename = this.resourcePath;
if (!('format' in options)) {
options.format = major_version >= 3 ? 'esm' : 'es';
const compileOptions = {
filename: this.resourcePath,
format: options.format || (major_version >= 3 ? 'esm' : 'es')
};
const handleWarning = warning => this.emitWarning(new Error(warning));
if (major_version >= 3) {
// TODO anything?
} else {
compileOptions.shared = options.shared || 'svelte/shared.js';
compileOptions.name = capitalize(sanitize(options.filename));
compileOptions.onwarn = options.onwarn || handleWarning;
}
if (!('shared' in options)) {
const shared = (major_version >= 3 ? 'svelte/internal.js' : 'svelte/shared.js');
options.shared = (options.format === 'es' || options.format === 'esm') &&
requireRelative.resolve(shared, process.cwd());
for (const option in options) {
if (!pluginOptions[option]) compileOptions[option] = options[option];
}
if (!('name' in options)) options.name = capitalize(sanitize(options.filename));
if (!('onwarn' in options)) options.onwarn = warning => this.emitWarning(new Error(warning));
if (options.emitCss) options.css = false;
if (options.externalDependencies) options.externalDependencies.forEach(dep => this.addDependency(dep));
deprecatePreprocessOptions(options);
options.preprocess.filename = options.filename;
options.preprocess.filename = compileOptions.filename;
preprocess(source, options.preprocess).then(processed => {
let { js, css } = normalize(compile(processed.toString(), options));
if (processed.dependencies && this.addDependency) {
for (let dependency of processed.dependencies) {
this.addDependency(dependency);
}
}
let { js, css, warnings } = normalize(compile(processed.toString(), compileOptions));
if (major_version >= 3) {
warnings.forEach(
options.onwarn
? warning => options.onwarn(warning, handleWarning)
: handleWarning
);
}
if (options.hotReload && !isProduction && !isServer) {
const hotOptions = Object.assign({}, options.hotOptions);
const id = JSON.stringify(relative(process.cwd(), options.filename));
const id = JSON.stringify(relative(process.cwd(), compileOptions.filename));
js.code = makeHot(id, js.code, hotOptions);

@@ -132,3 +164,3 @@ }

if (options.emitCss && css.code) {
const cssFilepath = options.filename.replace(
const cssFilepath = compileOptions.filename.replace(
/\.[^/.]+$/,

@@ -135,0 +167,0 @@ `.svelte.css`

{
"name": "svelte-loader",
"version": "2.12.0",
"version": "2.13.1",
"author": "Nico Rehwaldt <git_nikku@nixis.de>",

@@ -19,3 +19,2 @@ "description": "A webpack loader for svelte",

"loader-utils": "^1.1.0",
"require-relative": "^0.8.7",
"svelte-dev-helper": "^1.1.9"

@@ -30,3 +29,3 @@ },

"sinon-chai": "^3.2.0",
"svelte": "^2.9.5"
"svelte": "^3.0.0-beta.5"
},

@@ -33,0 +32,0 @@ "peerDependencies": {

@@ -74,4 +74,3 @@ /* global describe, it */

1: <p>Count: {count}</p>{/if}
^
2: <button on:click='set({ count: count + 1 })'>+1</button>`);
^`);

@@ -84,26 +83,2 @@ expect(code).not.to.exist;

it(
'should handle wrong export',
testLoader('test/fixtures/export-error.html', function(
err,
code,
map,
context
) {
expect(err).to.exist;
expect(err.message).to.eql(d`
ParseError: Unexpected token (5:7)
3: <script>
4: export {
5: foo: 'BAR'
^
6: };
7: </script>`);
expect(code).not.to.exist;
expect(map).not.to.exist;
})
);
it(
'should handle validation error',

@@ -118,10 +93,9 @@ testLoader('test/fixtures/validation-error.html', function(

expect(err.message).to.eql(d`
ValidationError: Computed properties can be function expressions or arrow function expressions (6:11)
4: export default {
5: computed: {
6: foo: 'BAR'
^
7: }
8: };`);
expect(err.message.trim()).to.eql(d`
ValidationError: A component cannot have a default export (2:1)
1: <script>
2: export default {};
^
3: </script>
4:`);

@@ -144,4 +118,3 @@ expect(code).not.to.exist;

// es2015 statements remain
expect(code).to.contain(`import { hello } from './utils';`);
expect(code).to.contain('data() {');
expect(code).to.contain(`import { hello } from "./utils";`);
})

@@ -156,3 +129,3 @@ );

// es2015 statements remain
expect(code).to.contain(`import Nested from './nested';`);
expect(code).to.contain(`import Nested from "./nested";`);

@@ -188,5 +161,5 @@ expect(code).to.exist;

describe('shared', () => {
describe('sveltePath', () => {
it(
'should configure shared=false (default)',
'should configure sveltePath',
testLoader(

@@ -197,21 +170,6 @@ 'test/fixtures/good.html',

expect(code).not.to.contain('import {');
expect(code).not.to.contain('svelte/shared.js');
},
{ shared: false },
1
)
);
it(
'should configure shared=true',
testLoader(
'test/fixtures/good.html',
function(err, code, map) {
expect(err).not.to.exist;
expect(code).to.contain('import {');
expect(code).to.contain('svelte/shared.js');
expect(code).to.contain('custom-svelte/internal');
},
{ shared: true }
{ sveltePath: 'custom-svelte' }
)

@@ -240,5 +198,3 @@ );

expect(code).to.contain(
'.render = function(state, options = {}) {'
);
expect(code).to.contain('create_ssr_component');
},

@@ -245,0 +201,0 @@ { generate: 'ssr' }

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc