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

css-codemod

Package Overview
Dependencies
Maintainers
1
Versions
34
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

css-codemod - npm Package Compare versions

Comparing version 0.0.0-pr.4.2.850b193 to 0.0.0-pr.4.3.b81c913

src/api.ts

47

dist/cli.js
#!/usr/bin/env node
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 __markAsModule = (target) => __defProp(target, "__esModule", { value: true });
var __reExport = (target, module2, copyDefault, desc) => {
if (module2 && typeof module2 === "object" || typeof module2 === "function") {
for (let key of __getOwnPropNames(module2))
if (!__hasOwnProp.call(target, key) && (copyDefault || key !== "default"))
__defProp(target, key, { get: () => module2[key], enumerable: !(desc = __getOwnPropDesc(module2, key)) || desc.enumerable });
}
return target;
};
var __toESM = (module2, isNodeMode) => {
return __reExport(__markAsModule(__defProp(module2 != null ? __create(__getProtoOf(module2)) : {}, "default", !isNodeMode && module2 && module2.__esModule ? { get: () => module2.default, enumerable: true } : { value: module2, enumerable: true })), module2);
};
// src/cli.ts
var import_cac = require("cac");
var import_fs = require("fs");
var import_fs2 = require("fs");
var import_path = require("path");
// src/process-transform.ts
var import_glob = __toESM(require("glob"));
var import_fs = __toESM(require("fs"));
// src/load-transform.ts

@@ -35,7 +57,22 @@ var import_bundle_require = require("bundle-require");

// src/api.ts
var import_postcss = __toESM(require("postcss"));
var parse = (source) => {
return import_postcss.default.parse(source);
};
var api = { parse };
// src/process-transform.ts
var processTransform = async (options) => {
console.log(options);
const transform = await loadTransform(options.transform);
transform();
const files = import_glob.default.sync(options.files);
files.map((file) => {
const source = import_fs.default.readFileSync(file, "utf8").toString();
const fileInfo = { path: file, source };
const result = transform(fileInfo, api);
console.log(result);
if (result !== null) {
import_fs.default.writeFileSync(file, result);
}
});
};

@@ -45,3 +82,3 @@

var PACKAGE_PATH = (0, import_path.join)(__dirname, "../package.json");
var PACKAGE_JSON = JSON.parse((0, import_fs.readFileSync)(PACKAGE_PATH, "utf8"));
var PACKAGE_JSON = JSON.parse((0, import_fs2.readFileSync)(PACKAGE_PATH, "utf8"));
var NAME = PACKAGE_JSON.name;

@@ -51,3 +88,3 @@ var VERSION = PACKAGE_JSON.version;

const cli = (0, import_cac.cac)(`${NAME}`);
cli.command("[files]", "File path to transform. Glob patterns are supported.").example(`${NAME} ./a.css`).example(`${NAME} ./src/a.css`).example(`${NAME} ./src/**/*.css`).example(`${NAME} ./**/*.css`).option("-t, --transform <transform>", "Path to the transform file", {
cli.command("[files]", "File path to transform. Note glob patterns are supported but must be wrapped in quotes.").example(`${NAME} ./a.css`).example(`${NAME} ./src/a.css`).example(`${NAME} "./src/**/*.css"`).example(`${NAME} "./**/*.css"`).option("-t, --transform <transform>", "Path to the transform file", {
default: "./transform.ts"

@@ -54,0 +91,0 @@ }).action(async (files, flags) => {

@@ -1,2 +0,2 @@

import { Plugin } from 'postcss';
import { Plugin, Root } from 'postcss';

@@ -6,2 +6,22 @@ declare type Processors = Omit<Plugin, 'postcssPlugin' | 'prepare'>;

export { Processors, traverse };
interface TransformAPI {
parse(source: string): Root;
}
interface TransformFileInfo {
/**
* The file path for the current file being transformed.
*/
path: string;
/**
* The file contents for the current file being transformed.
*/
source: string;
}
declare type Transform = (
/**
* Metadata for the current file being transformed.
*/
fileInfo: TransformFileInfo, api: TransformAPI) => null | string;
export { Processors, Transform, traverse };

3

package.json
{
"version": "0.0.0-pr.4.2.850b193",
"version": "0.0.0-pr.4.3.b81c913",
"license": "MIT",

@@ -39,2 +39,3 @@ "name": "css-codemod",

"devDependencies": {
"@types/glob": "^7.2.0",
"@types/node": "^17.0.13",

@@ -41,0 +42,0 @@ "dripip": "^0.10.0",

@@ -17,11 +17,14 @@ #!/usr/bin/env node

cli
.command('[files]', 'File path to transform. Glob patterns are supported.')
.command(
'[files]',
'File path to transform. Note glob patterns are supported but must be wrapped in quotes.'
)
.example(`${NAME} ./a.css`)
.example(`${NAME} ./src/a.css`)
.example(`${NAME} ./src/**/*.css`)
.example(`${NAME} ./**/*.css`)
.example(`${NAME} "./src/**/*.css"`)
.example(`${NAME} "./**/*.css"`)
.option('-t, --transform <transform>', 'Path to the transform file', {
default: './transform.ts',
})
.action(async (files: string[], flags) => {
.action(async (files: string, flags) => {
const { transform } = flags;

@@ -34,4 +37,4 @@

cli.version(VERSION);
cli.parse(process.argv, { run: false });
await cli.runMatchedCommand();

@@ -38,0 +41,0 @@ };

export { traverse, Processors } from './traverse';
export { Transform } from './transform';

@@ -0,8 +1,12 @@

import glob from 'glob';
import fs from 'fs';
import { loadTransform } from './load-transform';
import { TransformFileInfo } from './transform';
import { api } from './api';
interface ProcessTransformOptions {
/**
* The list of file paths to process and run through the transform.
* The file path to process and run through the transform.
*/
files: string[];
files: string;

@@ -16,6 +20,16 @@ /**

export const processTransform = async (options: ProcessTransformOptions) => {
console.log(options);
const transform = await loadTransform(options.transform);
const files = glob.sync(options.files);
transform();
files.map(file => {
const source = fs.readFileSync(file, 'utf8').toString();
const fileInfo: TransformFileInfo = { path: file, source };
const result = transform(fileInfo, api);
console.log(result);
if (result !== null) {
fs.writeFileSync(file, result);
}
});
};

@@ -1,8 +0,21 @@

interface TransformFileInfo {}
import { TransformAPI } from './api';
interface TransformAPI {}
export interface TransformFileInfo {
/**
* The file path for the current file being transformed.
*/
path: string;
/**
* The file contents for the current file being transformed.
*/
source: string;
}
export type Transform = (
/**
* Metadata for the current file being transformed.
*/
fileInfo: TransformFileInfo,
api: TransformAPI
) => null | string;
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