Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export function plugin(
options: IOptionalPreprocessOptions,
_preprocess = preprocess // for testing
) {
const allOptions = preprocessOptions(options);
return new Transform({
objectMode: true,
transform: function(file: Vinyl, enc, cb) {
if (file.isStream()) {
this.emit('error', new Error('@aurelia/plugin-gulp: Streaming is not supported'));
} else if (file.isBuffer()) {
// Rewrite foo.html to foo.html.js
const result = _preprocess(
{
path: file.relative,
contents: file.contents.toString(),
base: file.base
},
allOptions
);
export function plugin(options, _preprocess = preprocess // for testing
) {
const allOptions = preprocessOptions(options);
return new Transform({
objectMode: true,
transform: function (file, enc, cb) {
if (file.isStream()) {
this.emit('error', new Error('@aurelia/plugin-gulp: Streaming is not supported'));
}
else if (file.isBuffer()) {
// Rewrite foo.html to foo.html.js
const result = _preprocess({
path: file.relative,
contents: file.contents.toString(),
base: file.base
}, allOptions);
if (result) {
if (allOptions.templateExtensions.includes(file.extname)) {
// Rewrite foo.html to foo.html.js, or foo.md to foo.md.js
export function loader(
this: webpack.loader.LoaderContext,
contents: string,
_preprocess = preprocess // for testing
) {
// eslint-disable-next-line @typescript-eslint/no-unused-expressions, @typescript-eslint/strict-boolean-expressions
this.cacheable && this.cacheable();
const cb = this.async() as webpack.loader.loaderCallback;
const options = getOptions(this) as IOptionalPreprocessOptions;
const filePath = this.resourcePath;
try {
const result = _preprocess(
{ path: filePath, contents },
preprocessOptions(options || {})
);
// webpack uses source-map 0.6.1 typings for RawSourceMap which
// contains typing error version: string (should be number).
// use result.map as any to bypass the typing issue.
if (result) {
cb(null, result.code, result.map as any);
return;
}
// bypassed
cb(null, contents);
} catch (e) {
cb(e);
}
}
function loader(contents, _preprocess = plugin_conventions_1.preprocess // for testing
) {
// eslint-disable-next-line @typescript-eslint/no-unused-expressions, @typescript-eslint/strict-boolean-expressions
this.cacheable && this.cacheable();
const cb = this.async();
const options = loader_utils_1.getOptions(this);
const filePath = this.resourcePath;
try {
const result = _preprocess({ path: filePath, contents }, plugin_conventions_1.preprocessOptions(options || {}));
// webpack uses source-map 0.6.1 typings for RawSourceMap which
// contains typing error version: string (should be number).
// use result.map as any to bypass the typing issue.
if (result) {
cb(null, result.code, result.map);
return;
}
// bypassed
cb(null, contents);
}
catch (e) {
cb(e);
}
}
exports.loader = loader;
export function loader(contents, _preprocess = preprocess // for testing
) {
// eslint-disable-next-line @typescript-eslint/no-unused-expressions, @typescript-eslint/strict-boolean-expressions
this.cacheable && this.cacheable();
const cb = this.async();
const options = getOptions(this);
const filePath = this.resourcePath;
try {
const result = _preprocess({ path: filePath, contents }, preprocessOptions(options || {}));
// webpack uses source-map 0.6.1 typings for RawSourceMap which
// contains typing error version: string (should be number).
// use result.map as any to bypass the typing issue.
if (result) {
cb(null, result.code, result.map);
return;
}
// bypassed
cb(null, contents);
}
catch (e) {
cb(e);
}
}
//# sourceMappingURL=index.js.map
it('injects valueConverter decorator for non-kebab case file name', function () {
const code = `export class FooBarValueConverter {}\n`;
const expected = `import { valueConverter } from '@aurelia/runtime';
@valueConverter('fooBar')
export class FooBarValueConverter {}
`;
const result = preprocessResource(
{
path: path.join('bar', 'FooBar.js'),
contents: code,
filePair: 'FooBar.html'
},
preprocessOptions()
);
assert.equal(result.code, expected);
});
it('merges optional extensions', function () {
assert.deepEqual(
preprocessOptions({
cssExtensions: ['.css', '.some'],
jsExtensions: ['.mjs'],
templateExtensions: ['.markdown']
}),
{
cssExtensions: ['.css', '.less', '.sass', '.scss', '.some', '.styl'],
jsExtensions: ['.coffee', '.js', '.jsx', '.mjs', '.ts', '.tsx'],
templateExtensions: ['.haml', '.html', '.jade', '.markdown', '.md', '.pug', '.slim', '.slm'],
stringModuleWrap: undefined
}
);
});
it('gets value converter like resource', function() {
assert.deepEqual(nameConvention('FooBarValueConverter'), {
name: 'fooBar',
type: 'valueConverter'
});
assert.deepEqual(nameConvention('Foo1Bar23ValueConverter'), {
name: 'foo1Bar23',
type: 'valueConverter'
});
});
it('gets custom attribute like resource', function() {
assert.deepEqual(nameConvention('FooBarCustomAttribute'), {
name: 'foo-bar',
type: 'customAttribute'
});
assert.deepEqual(nameConvention('Foo1BarCustomAttribute'), {
name: 'foo1-bar',
type: 'customAttribute'
});
});
it('gets custom element like resource', function() {
assert.deepEqual(nameConvention('FooBar'), {
name: 'foo-bar',
type: 'customElement'
});
assert.deepEqual(nameConvention('FooBar123'), {
name: 'foo-bar123',
type: 'customElement'
});
});