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

parcel-codegen-loader

Package Overview
Dependencies
Maintainers
0
Versions
68
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

parcel-codegen-loader - npm Package Compare versions

Comparing version 1.0.1 to 2.0.0-pre.1

3

lib/index.d.ts

@@ -1,4 +0,1 @@

export interface DependencyOptions {
includedInParent?: boolean;
}
export default function loader(source: string, map: string, meta: any): Promise<void>;

162

lib/index.js

@@ -1,45 +0,127 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const validateOptions = require("schema-utils");
const loader_utils_1 = require("loader-utils");
const schema = {
type: 'object',
properties: {},
additionalProperties: false,
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
function reloadGenerator(name) {
delete require.cache[require.resolve(name)];
return require(name);
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// src/index.ts
var index_exports = {};
__export(index_exports, {
default: () => loader
});
module.exports = __toCommonJS(index_exports);
var validateOptions = __toESM(require("schema-utils"));
var import_loader_utils = require("loader-utils");
// ../codegen-lib/lib/esm/index.mjs
var import_module = require("module");
function reloadGenerator(requireModule, name) {
const path = requireModule.resolve(name);
delete requireModule.cache[path];
return requireModule(name);
}
function noop() {
}
function createCodegenHost(fileOrDirName) {
const requireModule = (0, import_module.createRequire)(fileOrDirName);
const host = {
load(name, type) {
switch (type) {
case "cjs":
return Promise.resolve(reloadGenerator(requireModule, name));
case "esm":
return import(name).then((result) => result.default || result);
case "auto":
default:
if (name.endsWith(".mjs.codegen") || name.endsWith(".esm.codegen") || name.endsWith(".module.codegen") || name.endsWith(".m.codegen")) {
return host.load(name, "esm");
}
return host.load(name, "cjs");
}
},
async generate(details) {
const { name, type = "auto", options = {}, addDependency = noop } = details;
if (typeof name !== "string") {
throw new Error(`You need to pass in a string for "name". Received: "${name}".`);
}
const generator = await host.load(name, type);
if (typeof generator !== "function") {
throw new Error(`The codegen module "${name}" does not export a function and is invalid.`);
}
const result = await generator.call({
name,
options,
addDependency
});
if (typeof result === "string") {
const type2 = typeof generator.type === "string" ? generator.type : "js";
return {
type: type2,
value: result
};
}
if (result && typeof result === "object" && typeof result.value === "string" && typeof result.type === "string") {
return result;
}
throw new Error(
`The codegen module "${name}" did not generate a valid result (string or object). It returned: "${result}".`
);
}
};
return host;
}
// src/index.ts
var schema = {
type: "object",
properties: {},
additionalProperties: false
};
var rootDir = process.cwd();
var codegen = createCodegenHost(rootDir);
async function loader(source, map, meta) {
const options = (0, loader_utils_1.getOptions)(this);
validateOptions(schema, options, {
name: 'Codegen Loader',
baseDataPath: 'options',
const options = (0, import_loader_utils.getOptions)(this);
validateOptions(schema, options, {
name: "Codegen Loader",
baseDataPath: "options"
});
const name = this.resourcePath;
const compiler = this._compiler;
const callback = this.async();
try {
const content = await codegen.generate({
name,
options: {
outDir: compiler?.options?.output?.path,
rootDir
},
addDependency: (file) => this.addDependency(file)
});
const name = this.resourcePath;
const compiler = this._compiler;
const callback = this.async();
try {
const generator = reloadGenerator(name);
const content = await generator.call({
name,
options: {
outDir: compiler?.options?.output?.path,
rootDir: process.cwd(),
},
addDependency: (file, options = {}) => this.addDependency(file),
});
if (typeof content === 'string') {
callback(null, content, map, meta);
}
else {
callback(new Error('Unsupported return type from codegen.'), source);
}
}
catch (err) {
callback(err, source);
}
callback(null, content.value, map, meta);
} catch (err) {
callback(err, source);
}
}
exports.default = loader;
//# sourceMappingURL=index.js.map
//# sourceMappingURL=index.js.map
{
"name": "parcel-codegen-loader",
"version": "1.0.1",
"description": "A loader for .codegen files to auto-generate modules on the fly.",
"version": "2.0.0-pre.1",
"description": "A plugin for Webpack (v4 and higher) to generate useful modules at bundle-time.",
"source": "src/index.ts",
"main": "lib/index.js",
"typings": "lib/index.d.ts",
"scripts": {
"build": "tsc",
"test": "echo \"Error: no test specified\" && exit 1"
"test": "tsc --noEmit",
"build": "npm run build:cjs && npm run build:types",
"build:cjs": "esbuild 'src/index.ts' --sourcemap --bundle --platform=node --format=cjs --external:loader-utils --external:schema-utils --outdir=lib",
"build:types": "tsc --emitDeclarationOnly"
},
"author": "smapiot",
"homepage": "https://piral.io",
"author": "Florian Rappl",
"license": "MIT",
"engines": {
"node": ">=14.0"
"node": ">=16.0"
},

@@ -23,10 +25,10 @@ "files": [

"type": "github",
"url": "https://github.com/sponsors/smapiot"
"url": "https://github.com/sponsors/FlorianRappl"
},
"repository": {
"type": "git",
"url": "git+https://github.com/smapiot/piral-cli-webpack.git"
"url": "git+https://github.com/FlorianRappl/codegen-js.git"
},
"bugs": {
"url": "https://github.com/smapiot/piral-cli-webpack/issues"
"url": "https://github.com/FlorianRappl/codegen-js/issues"
},

@@ -38,13 +40,11 @@ "keywords": [

],
"peerDependencies": {
"webpack": "4.x || 5.x"
"dependencies": {
"loader-utils": "^2.0.0",
"schema-utils": "^2.6.5"
},
"devDependencies": {
"codegen-lib": "2.0.0-pre.1",
"webpack": "^4.42.0"
},
"dependencies": {
"loader-utils": "^2.0.0",
"schema-utils": "^2.6.5"
},
"gitHead": "6afb1cbda3385aead4783a770775ac1770dc244a"
"gitHead": "e4d5f09fa24333b77325210da77f9809dbd5d12f"
}

@@ -7,9 +7,8 @@ <div align="center">

[![npm][npm]][npm-url]
[![node][node]][node-url]
[![chat][chat]][chat-url]
[![size][size]][size-url]
# parcel-codegen-loader
[![npm](https://img.shields.io/npm/v/parcel-codegen-loader.svg)](https://www.npmjs.com/package/parcel-codegen-loader)
[![GitHub tag](https://img.shields.io/github/tag/FlorianRappl/codegen-js.svg)](https://github.com/FlorianRappl/codegen-js/releases)
[![GitHub issues](https://img.shields.io/github/issues/FlorianRappl/codegen-js.svg)](https://github.com/FlorianRappl/codegen-js/issues)
The `parcel-codegen-loader` resolves `import` / `require()` on a file into a Node.js module that is evaluated during the compilation. It expects the Node.js module to generate a webpack module on the fly establishing meta programming.

@@ -105,15 +104,4 @@

Just make sure to post an issue or reach out to me on [Gitter](https://gitter.im/piral-io/community) before starting actual work on anything. It really helps to avoid problems.
## License
This plugin is released using the MIT license.
[npm]: https://img.shields.io/npm/v/parcel-codegen-loader.svg
[npm-url]: https://npmjs.com/package/parcel-codegen-loader
[node]: https://img.shields.io/node/v/parcel-codegen-loader.svg
[node-url]: https://nodejs.org
[chat]: https://img.shields.io/badge/gitter-piral.io%2Fcommunity-brightgreen.svg
[chat-url]: https://gitter.im/piral-io/community
[size]: https://packagephobia.now.sh/badge?p=parcel-codegen-loader
[size-url]: https://packagephobia.now.sh/result?p=parcel-codegen-loader
This plugin is released using the MIT license. For more information see the [LICENSE file](./LICENSE).
import * as validateOptions from 'schema-utils';
import { getOptions } from 'loader-utils';
import { Compiler } from 'webpack';
import { createCodegenHost } from 'codegen-lib';
import type { Compiler } from 'webpack';

@@ -11,11 +12,5 @@ const schema = {

function reloadGenerator(name: string) {
delete require.cache[require.resolve(name)];
return require(name);
}
const rootDir = process.cwd();
const codegen = createCodegenHost(rootDir);
export interface DependencyOptions {
includedInParent?: boolean;
}
export default async function loader(source: string, map: string, meta: any) {

@@ -34,17 +29,12 @@ const options = getOptions(this);

try {
const generator = reloadGenerator(name);
const content = await generator.call({
const content = await codegen.generate({
name,
options: {
outDir: compiler?.options?.output?.path,
rootDir: process.cwd(),
rootDir,
},
addDependency: (file: string, options: DependencyOptions = {}) => this.addDependency(file),
addDependency: (file) => this.addDependency(file),
});
if (typeof content === 'string') {
callback(null, content, map, meta);
} else {
callback(new Error('Unsupported return type from codegen.'), source);
}
callback(null, content.value, map, meta);
} catch (err) {

@@ -51,0 +41,0 @@ callback(err, source);

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