css-codemod
Advanced tools
Comparing version 0.0.0-pr.5.1.a62f07b to 0.0.0-pr.5.2.7ad0f2c
@@ -62,3 +62,3 @@ #!/usr/bin/env node | ||
var validateTransform = (transform) => { | ||
if (typeof transform === "function") { | ||
if (typeof transform === "function" && transform.length <= 2) { | ||
return transform; | ||
@@ -65,0 +65,0 @@ } else { |
@@ -1,7 +0,7 @@ | ||
import { Plugin, Root } from 'postcss'; | ||
import { Root } from 'postcss'; | ||
declare type Processors = Omit<Plugin, 'postcssPlugin' | 'prepare'>; | ||
declare const traverse: (css: string, processors: Processors) => Promise<string | null>; | ||
interface TransformAPI { | ||
/** | ||
* Parse a raw CSS string into an abstract syntax tree and return a PostCSS `Root` node. | ||
*/ | ||
parse(source: string): Root; | ||
@@ -31,2 +31,2 @@ } | ||
export { Processors, Transform, traverse }; | ||
export { Transform }; |
@@ -1,26 +0,6 @@ | ||
var __create = Object.create; | ||
var __defProp = Object.defineProperty; | ||
var __getOwnPropDesc = Object.getOwnPropertyDescriptor; | ||
var __getOwnPropNames = Object.getOwnPropertyNames; | ||
var __getOwnPropSymbols = Object.getOwnPropertySymbols; | ||
var __getProtoOf = Object.getPrototypeOf; | ||
var __hasOwnProp = Object.prototype.hasOwnProperty; | ||
var __propIsEnum = Object.prototype.propertyIsEnumerable; | ||
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value; | ||
var __spreadValues = (a, b) => { | ||
for (var prop in b || (b = {})) | ||
if (__hasOwnProp.call(b, prop)) | ||
__defNormalProp(a, prop, b[prop]); | ||
if (__getOwnPropSymbols) | ||
for (var prop of __getOwnPropSymbols(b)) { | ||
if (__propIsEnum.call(b, prop)) | ||
__defNormalProp(a, prop, b[prop]); | ||
} | ||
return a; | ||
}; | ||
var __markAsModule = (target) => __defProp(target, "__esModule", { value: true }); | ||
var __export = (target, all) => { | ||
for (var name in all) | ||
__defProp(target, name, { get: all[name], enumerable: true }); | ||
}; | ||
var __reExport = (target, module2, copyDefault, desc) => { | ||
@@ -34,5 +14,2 @@ if (module2 && typeof module2 === "object" || typeof module2 === "function") { | ||
}; | ||
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); | ||
}; | ||
var __toCommonJS = /* @__PURE__ */ ((cache) => { | ||
@@ -46,37 +23,5 @@ return (module2, temp) => { | ||
var src_exports = {}; | ||
__export(src_exports, { | ||
traverse: () => traverse | ||
}); | ||
// src/traverse/index.ts | ||
var import_postcss = __toESM(require("postcss")); | ||
var createTransformPlugin = (processors) => __spreadValues({ | ||
postcssPlugin: "css-codemod-plugin" | ||
}, processors); | ||
var traverse = async (css, processors) => { | ||
try { | ||
const plugins = [createTransformPlugin(processors)]; | ||
const processor = (0, import_postcss.default)(plugins); | ||
const result = await processor.process(css, { | ||
from: void 0 | ||
}); | ||
return result.css; | ||
} catch (err) { | ||
console.error(`Unexpected error processing CSS. | ||
CSS string: | ||
${css} | ||
Error: | ||
${err}`); | ||
} | ||
return null; | ||
}; | ||
// src/transform.ts | ||
var import_bundle_require = require("bundle-require"); | ||
module.exports = __toCommonJS(src_exports); | ||
// Annotate the CommonJS export names for ESM import in node: | ||
0 && (module.exports = { | ||
traverse | ||
}); |
{ | ||
"version": "0.0.0-pr.5.1.a62f07b", | ||
"version": "0.0.0-pr.5.2.7ad0f2c", | ||
"license": "MIT", | ||
@@ -22,2 +22,3 @@ "name": "css-codemod", | ||
"test": "tsdx test", | ||
"test:watch": "tsdx test --watch", | ||
"lint": "tsdx lint", | ||
@@ -39,2 +40,6 @@ "prepare": "yarn build", | ||
}, | ||
"resolutions": { | ||
"**/tsdx/jest": "27.4.7", | ||
"**/tsdx/ts-jest": "27.1.3" | ||
}, | ||
"devDependencies": { | ||
@@ -41,0 +46,0 @@ "@types/glob": "^7.2.0", |
import postcss, { Root } from 'postcss'; | ||
export interface TransformAPI { | ||
/** | ||
* Parse a raw CSS string into an abstract syntax tree and return a PostCSS `Root` node. | ||
*/ | ||
parse(source: string): Root; | ||
@@ -5,0 +8,0 @@ } |
@@ -16,2 +16,5 @@ import fs from 'fs'; | ||
/** | ||
* Construct file metadata given a file path. | ||
*/ | ||
export const getFileInfo = (file: string): TransformFileInfo => { | ||
@@ -27,2 +30,5 @@ try { | ||
/** | ||
* Write contents to the given file. | ||
*/ | ||
export const writeFile = (file: string, contents: string): void => { | ||
@@ -36,2 +42,5 @@ try { | ||
/** | ||
* Return an array of file paths that matches the given files string. | ||
*/ | ||
export const getAllFilesToTransform = (files: string) => glob.sync(files); |
@@ -1,2 +0,1 @@ | ||
export { traverse, Processors } from './traverse'; | ||
export { Transform } from './transform'; |
@@ -26,4 +26,4 @@ import { bundleRequire } from 'bundle-require'; | ||
*/ | ||
const validateTransform = (transform: unknown): Transform => { | ||
if (typeof transform === 'function') { | ||
export const validateTransform = (transform: unknown): Transform => { | ||
if (typeof transform === 'function' && transform.length <= 2) { | ||
return transform as Transform; | ||
@@ -30,0 +30,0 @@ } else { |
18702
13
333