New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@wgslx/wgslx-loader

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@wgslx/wgslx-loader - npm Package Compare versions

Comparing version 0.0.3 to 0.0.5

8

dist/index.js

@@ -21,11 +21,9 @@ "use strict";

this.getOptions();
const token = wgslx_1.Syntax.translationUnitExtended.matchAll(source, this.resourcePath);
const text = (0, wgslx_1.preprocess)(source);
const token = wgslx_1.Syntax.translationUnitExtended.matchAll(text, this.resourcePath);
if (token === null) {
throw new Error('Failed to parse the shader source.');
}
return [
`const shader = {code:\`${token.toString(true)}\`};`,
'module.exports = shader;'
].join('\n');
return [`const shader = {code:\`${(0, wgslx_1.postprocess)(token)}\`};`, 'module.exports = shader;'].join('\n');
}
exports.default = wgslxLoader;
{
"name": "@wgslx/wgslx-loader",
"version": "0.0.3",
"version": "0.0.5",
"description": "Webpack loader for wgsl, wgslx, and wgsli files.",

@@ -9,3 +9,3 @@ "main": "dist/index.js",

"build": "npx tsc --build",
"generate": "npx ts-node scripts/generate.ts",
"prepare": "npm run test && npm run build",
"test": "npx jest"

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

"dependencies": {
"@wgslx/wgslx": "^0.0.2"
"@wgslx/wgslx": "^0.0.5"
},

@@ -42,2 +42,2 @@ "devDependencies": {

}
}
}
import * as webpack from 'webpack';
import { Context, Cursor, Syntax } from '@wgslx/wgslx';
import { Context, Cursor, Syntax, postprocess, preprocess } from '@wgslx/wgslx';

@@ -7,4 +7,3 @@ export * from './shader';

interface LoaderOptions {
// Add loader options here.
// Add loader options here.
}

@@ -14,14 +13,14 @@

export default function wgslxLoader(this: webpack.LoaderContext<LoaderOptions>, source: string) {
this.getOptions();
this.getOptions();
const token = Syntax.translationUnitExtended.matchAll(source, this.resourcePath);
const text = preprocess(source);
const token = Syntax.translationUnitExtended.matchAll(text, this.resourcePath);
if (token === null) {
throw new Error('Failed to parse the shader source.');
}
if (token === null) {
throw new Error('Failed to parse the shader source.');
}
return [
`const shader = {code:\`${token.toString(true)}\`};`,
'module.exports = shader;'
].join('\n');
}
return [`const shader = {code:\`${postprocess(token)}\`};`, 'module.exports = shader;'].join(
'\n'
);
}
/** Shader module. */
export interface WgslxShader {
/** Shader source. */
readonly code: string;
/** Shader source. */
readonly code: string;
/** Shader label derived from the file name. */
readonly label?: string;
/** Shader label derived from the file name. */
readonly label?: string;
/** Shader source map if configured to be generated. */
readonly sourceMap?: string;
/** Shader source map if configured to be generated. */
readonly sourceMap?: string;
}

@@ -7,43 +7,43 @@ import { resolve } from 'path';

function compileAsync(compiler: Compiler) {
return new Promise((resolve, reject) => {
compiler.run((error: Error | null, stats?: Stats) => {
if (error || stats?.hasErrors()) {
const resolvedError = error || stats?.toJson('errors-only')[0]
reject(resolvedError.message)
}
return new Promise((resolve, reject) => {
compiler.run((error: Error | null, stats?: Stats) => {
if (error || stats?.hasErrors()) {
const resolvedError = error || stats?.toJson('errors-only')[0];
reject(resolvedError.message);
}
resolve(stats)
})
})
resolve(stats);
});
});
}
describe('wgslx-loader', () => {
it('compiles', async () => {
// Configure a webpack compiler.
const compiler = webpack({
mode: 'development',
entry: resolve(__dirname, './data/basic.wgsl'),
output: { filename: 'basic.wgsl' },
module: {
rules: [
{
test: /\.wgsl$/,
use: [require.resolve('../src/index.ts')],
},
],
},
});
it('compiles', async () => {
// Configure a webpack compiler.
const compiler = webpack({
mode: 'development',
entry: resolve(__dirname, './data/basic.wgsl'),
output: { filename: 'basic.wgsl' },
module: {
rules: [
{
test: /\.wgsl$/,
use: [require.resolve('../src/index.ts')],
},
],
},
});
// Create an in-memory file system so that the build assets
// are not emitted to disk during test runs.
const memoryFs = createFsFromVolume(new Volume());
compiler.outputFileSystem = memoryFs as any;
// Create an in-memory file system so that the build assets
// are not emitted to disk during test runs.
const memoryFs = createFsFromVolume(new Volume());
compiler.outputFileSystem = memoryFs as any;
// Compile the bundle.
await compileAsync(compiler);
// Compile the bundle.
await compileAsync(compiler);
// Expect the compiled code to create an "audio" element in React.
const compiledCode = memoryFs.readFileSync('dist/basic.wgsl', 'utf8');
expect(compiledCode).toContain('hello world');
}, 10000);
});
// Expect the compiled code to create an "audio" element in React.
const compiledCode = memoryFs.readFileSync('dist/basic.wgsl', 'utf8');
expect(compiledCode).toContain('vertex fn main');
}, 10000);
});

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