babel-plugin-knifecycle
Advanced tools
Comparing version 5.0.3 to 5.0.4
@@ -0,1 +1,5 @@ | ||
## [5.0.4](https://github.com/nfroidure/babel-plugin-knifecycle/compare/v5.0.3...v5.0.4) (2024-08-10) | ||
## [5.0.3](https://github.com/nfroidure/babel-plugin-knifecycle/compare/v5.0.2...v5.0.3) (2022-05-25) | ||
@@ -2,0 +6,0 @@ |
@@ -1,183 +0,161 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.default = knifecyclePlugin; | ||
var _util = require("knifecycle/dist/util"); | ||
import { parseName } from 'knifecycle'; | ||
const commonTransform = (babel, autoFunctionPath, functionDefinitionPath) => { | ||
const name = _pickupHandlerName(functionDefinitionPath); | ||
const injections = _pickupInitializerDependencies(functionDefinitionPath); | ||
autoFunctionPath.node.arguments = [ | ||
autoFunctionPath.node.arguments[0], | ||
babel.types.stringLiteral(parseName(name)), | ||
babel.types.arrayExpression(injections.map((i) => babel.types.stringLiteral(i))), | ||
...autoFunctionPath.node.arguments.slice(1), | ||
]; | ||
}; | ||
const AUTO_FUNCTIONS_TRANFORMS = { | ||
autoInject: { | ||
target: 'inject', | ||
transform: (babel, autoFunctionPath, functionDefinitionPath) => { | ||
const injections = _pickupInitializerDependencies(functionDefinitionPath); | ||
autoFunctionPath.node.arguments.unshift(babel.types.arrayExpression(injections.map(i => babel.types.stringLiteral(i)))); | ||
} | ||
}, | ||
autoName: { | ||
target: 'name', | ||
transform: (babel, autoFunctionPath, functionDefinitionPath) => { | ||
const name = _pickupHandlerName(functionDefinitionPath); | ||
autoFunctionPath.node.arguments.unshift(babel.types.stringLiteral((0, _util.parseName)(name))); | ||
} | ||
}, | ||
autoService: { | ||
target: 'service', | ||
transform: (babel, autoFunctionPath, functionDefinitionPath) => { | ||
const name = _pickupHandlerName(functionDefinitionPath); | ||
const injections = _pickupInitializerDependencies(functionDefinitionPath); | ||
autoFunctionPath.node.arguments = [autoFunctionPath.node.arguments[0], babel.types.stringLiteral((0, _util.parseName)(name)), babel.types.arrayExpression(injections.map(i => babel.types.stringLiteral(i))), ...autoFunctionPath.node.arguments.slice(1)]; | ||
} | ||
} | ||
autoInject: { | ||
target: 'inject', | ||
transform: (babel, autoFunctionPath, functionDefinitionPath) => { | ||
const injections = _pickupInitializerDependencies(functionDefinitionPath); | ||
autoFunctionPath.node.arguments.unshift(babel.types.arrayExpression(injections.map((i) => babel.types.stringLiteral(i)))); | ||
}, | ||
}, | ||
autoName: { | ||
target: 'name', | ||
transform: (babel, autoFunctionPath, functionDefinitionPath) => { | ||
const name = _pickupHandlerName(functionDefinitionPath); | ||
autoFunctionPath.node.arguments.unshift(babel.types.stringLiteral(parseName(name))); | ||
}, | ||
}, | ||
autoService: { | ||
target: 'service', | ||
transform: commonTransform, | ||
}, | ||
autoHandler: { | ||
target: 'handler', | ||
transform: commonTransform, | ||
}, | ||
autoProvider: { | ||
target: 'provider', | ||
transform: commonTransform, | ||
}, | ||
}; | ||
AUTO_FUNCTIONS_TRANFORMS.autoHandler = { | ||
target: 'handler', | ||
transform: AUTO_FUNCTIONS_TRANFORMS.autoService.transform | ||
target: 'handler', | ||
transform: AUTO_FUNCTIONS_TRANFORMS.autoService.transform, | ||
}; | ||
AUTO_FUNCTIONS_TRANFORMS.autoProvider = { | ||
target: 'provider', | ||
transform: AUTO_FUNCTIONS_TRANFORMS.autoService.transform | ||
target: 'provider', | ||
transform: AUTO_FUNCTIONS_TRANFORMS.autoService.transform, | ||
}; | ||
function knifecyclePlugin(babel) { | ||
return { | ||
visitor: { | ||
Program(programPath) { | ||
programPath.traverse({ | ||
ImportDeclaration(path) { | ||
const sourceNode = path.get('source'); | ||
if (!sourceNode.isStringLiteral()) { | ||
return; | ||
} | ||
if (!sourceNode.node.value === 'knifecycle') { | ||
return; | ||
} | ||
path.traverse({ | ||
ImportSpecifier(path) { | ||
const localNode = path.get('local'); | ||
const importedNode = path.get('imported'); | ||
if (!(localNode.isIdentifier() && importedNode.isIdentifier())) { | ||
return; | ||
} | ||
const autoFunctionName = importedNode.node.name; | ||
if (AUTO_FUNCTIONS_TRANFORMS[autoFunctionName]) { | ||
_renameAutoFunction(path, importedNode, localNode, AUTO_FUNCTIONS_TRANFORMS[autoFunctionName].target); | ||
_forEachCallExpression(path, localNode, path => { | ||
const functionDefinitionPath = _findFunctionDefinitionPath(path); | ||
AUTO_FUNCTIONS_TRANFORMS[autoFunctionName].transform(babel, path, functionDefinitionPath); | ||
}); | ||
} | ||
} | ||
}); | ||
} | ||
}); | ||
} | ||
} | ||
}; | ||
export default function knifecyclePlugin(babel) { | ||
return { | ||
visitor: { | ||
Program(programPath) { | ||
programPath.traverse({ | ||
ImportDeclaration(path) { | ||
const sourceNode = path.get('source'); | ||
if (!sourceNode.isStringLiteral()) { | ||
return; | ||
} | ||
if (sourceNode.node.value !== 'knifecycle') { | ||
return; | ||
} | ||
path.traverse({ | ||
ImportSpecifier(path) { | ||
const localNode = path.get('local'); | ||
const importedNode = path.get('imported'); | ||
if (!(localNode.isIdentifier() && importedNode.isIdentifier())) { | ||
return; | ||
} | ||
const autoFunctionName = importedNode.node.name; | ||
if (AUTO_FUNCTIONS_TRANFORMS[autoFunctionName]) { | ||
_renameAutoFunction(path, importedNode, localNode, AUTO_FUNCTIONS_TRANFORMS[autoFunctionName].target); | ||
_forEachCallExpression(path, localNode, (path) => { | ||
const functionDefinitionPath = _findFunctionDefinitionPath(path); | ||
AUTO_FUNCTIONS_TRANFORMS[autoFunctionName].transform(babel, path, functionDefinitionPath); | ||
}); | ||
} | ||
}, | ||
}); | ||
}, | ||
}); | ||
}, | ||
}, | ||
}; | ||
} | ||
function _renameAutoFunction(path, importedNode, localNode, name) { | ||
importedNode.node.name = name; | ||
path.scope.rename(localNode.node.name, path.scope.generateUidIdentifier(name).name); | ||
importedNode.node.name = name; | ||
path.scope.rename(localNode.node.name, path.scope.generateUidIdentifier(name).name); | ||
} | ||
function _forEachCallExpression(path, localNode, fn) { | ||
const binding = path.scope.getBinding(localNode.node.name); | ||
binding.referencePaths.forEach(path => { | ||
if (!path.parentPath.isCallExpression()) { | ||
return; | ||
} | ||
fn(path.parentPath); | ||
}); | ||
const binding = path.scope.getBinding(localNode.node.name); | ||
binding.referencePaths.forEach((path) => { | ||
if (!path.parentPath.isCallExpression()) { | ||
return; | ||
} | ||
fn(path.parentPath); | ||
}); | ||
} | ||
function _findFunctionDefinitionPath(path) { | ||
const autoHandlerArgumentPath = path.get('arguments.0'); | ||
let functionDefinitionPath; | ||
if (autoHandlerArgumentPath.isIdentifier()) { | ||
const binding = autoHandlerArgumentPath.scope.getBinding(autoHandlerArgumentPath.node.name); | ||
if (!(binding && (binding.path.isFunctionDeclaration() || binding.path.isVariableDeclarator()))) { | ||
throw autoHandlerArgumentPath.buildCodeFrameError('Expect the function passed in autoHandler to be defined in the local file.'); | ||
const autoHandlerArgumentPath = path.get('arguments.0'); | ||
let functionDefinitionPath; | ||
if (autoHandlerArgumentPath.isIdentifier()) { | ||
const binding = autoHandlerArgumentPath.scope.getBinding(autoHandlerArgumentPath.node.name); | ||
if (!(binding && | ||
(binding.path.isFunctionDeclaration() || | ||
binding.path.isVariableDeclarator()))) { | ||
throw autoHandlerArgumentPath.buildCodeFrameError('Expect the function passed in autoHandler to be defined in the local file.'); | ||
} | ||
if (binding.path.isFunctionDeclaration()) { | ||
functionDefinitionPath = binding.path; | ||
} | ||
else { | ||
functionDefinitionPath = binding.path.get('init'); | ||
if (!functionDefinitionPath.isFunctionExpression()) { | ||
throw autoHandlerArgumentPath.buildCodeFrameError('Expect the function passed in autoHandler to be defined in the local file.'); | ||
} | ||
if (!functionDefinitionPath.get('id').node) { | ||
functionDefinitionPath.get('id').replaceWith({ | ||
type: 'Identifier', | ||
name: binding.path.get('id').node.name, | ||
}); | ||
} | ||
} | ||
} | ||
if (binding.path.isFunctionDeclaration()) { | ||
functionDefinitionPath = binding.path; | ||
} else { | ||
functionDefinitionPath = binding.path.get('init'); | ||
if (!functionDefinitionPath.isFunctionExpression()) { | ||
throw autoHandlerArgumentPath.buildCodeFrameError('Expect the function passed in autoHandler to be defined in the local file.'); | ||
} | ||
if (!functionDefinitionPath.get('id').node) { | ||
functionDefinitionPath.get('id').replaceWith({ | ||
type: 'Identifier', | ||
name: binding.path.get('id').node.name | ||
}); | ||
} | ||
else if (autoHandlerArgumentPath.isFunctionExpression()) { | ||
functionDefinitionPath = autoHandlerArgumentPath; | ||
} | ||
} else if (autoHandlerArgumentPath.isFunctionExpression()) { | ||
functionDefinitionPath = autoHandlerArgumentPath; | ||
} else if (autoHandlerArgumentPath.isCallExpression()) { | ||
const calleeName = autoHandlerArgumentPath.get('callee').node.name; | ||
if (!AUTO_FUNCTIONS_TRANFORMS[calleeName]) { | ||
throw autoHandlerArgumentPath.buildCodeFrameError('Expect autoHandler to take an auto function call in argument, try to import the auto function in the same order they were used.'); | ||
else if (autoHandlerArgumentPath.isCallExpression()) { | ||
const calleeName = autoHandlerArgumentPath.get('callee').node.name; | ||
if (!AUTO_FUNCTIONS_TRANFORMS[calleeName]) { | ||
throw autoHandlerArgumentPath.buildCodeFrameError('Expect autoHandler to take an auto function call in argument, try to import the auto function in the same order they were used.'); | ||
} | ||
return _findFunctionDefinitionPath(autoHandlerArgumentPath); | ||
} | ||
return _findFunctionDefinitionPath(autoHandlerArgumentPath); | ||
} else { | ||
throw autoHandlerArgumentPath.buildCodeFrameError('Expect autoHandler to take an async function in argument.'); | ||
} | ||
return functionDefinitionPath; | ||
else { | ||
throw autoHandlerArgumentPath.buildCodeFrameError('Expect autoHandler to take an async function in argument.'); | ||
} | ||
return functionDefinitionPath; | ||
} | ||
function _pickupHandlerName(path) { | ||
return path.get('id').node.name; | ||
return path.get('id').node.name; | ||
} | ||
function _pickupInitializerDependencies(path) { | ||
const injections = []; | ||
const handlerArgumentPath = path.get('params.0'); | ||
if (!handlerArgumentPath) { | ||
return injections; | ||
} | ||
if (!handlerArgumentPath.isObjectPattern()) { | ||
if (handlerArgumentPath.node.name === '_') { | ||
return injections; | ||
const injections = []; | ||
const handlerArgumentPath = path.get('params.0'); | ||
if (!handlerArgumentPath) { | ||
return injections; | ||
} | ||
throw handlerArgumentPath.buildCodeFrameError('Expect the dependencies to be defined through an object pattern.'); | ||
} | ||
handlerArgumentPath.traverse({ | ||
Property(path) { | ||
injections.push((path.get('value').isAssignmentPattern() ? '?' : '') + path.get('key').node.name); | ||
if (!handlerArgumentPath.isObjectPattern()) { | ||
if (handlerArgumentPath.node.name === '_') { | ||
return injections; | ||
} | ||
throw handlerArgumentPath.buildCodeFrameError('Expect the dependencies to be defined through an object pattern.'); | ||
} | ||
}); | ||
return injections; | ||
handlerArgumentPath.traverse({ | ||
Property(path) { | ||
injections.push((path.get('value').isAssignmentPattern() ? '?' : '') + | ||
path.get('key').node.name); | ||
}, | ||
}); | ||
return injections; | ||
} | ||
//# sourceMappingURL=index.js.map |
@@ -1,14 +0,8 @@ | ||
"use strict"; | ||
var _core = require("@babel/core"); | ||
var _ = _interopRequireDefault(require(".")); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
// src/__tests__/index-test.js | ||
import { describe, test, expect } from '@jest/globals'; | ||
import { transform } from '@babel/core'; | ||
import plugin from './index.js'; | ||
describe('babel-plugin-knifecycle', () => { | ||
describe('autoInject', () => { | ||
it('should work with es6 modules imports', () => { | ||
var example = ` | ||
describe('autoInject', () => { | ||
test('should work with es6 modules imports', () => { | ||
const example = ` | ||
import noop from 'noop'; | ||
@@ -23,11 +17,9 @@ import { autoInject } from 'knifecycle'; | ||
`; | ||
const { | ||
code | ||
} = (0, _core.transform)(example, { | ||
plugins: [_.default] | ||
}); | ||
expect(code).toMatchSnapshot(); | ||
}); | ||
it('should work with object rest spreads', () => { | ||
var example = ` | ||
const { code } = transform(example, { | ||
plugins: [plugin], | ||
}); | ||
expect(code).toMatchSnapshot(); | ||
}); | ||
test('should work with object rest spreads', () => { | ||
const example = ` | ||
import noop from 'noop'; | ||
@@ -42,25 +34,22 @@ import { autoInject } from 'knifecycle'; | ||
`; | ||
const { | ||
code | ||
} = (0, _core.transform)(example, { | ||
plugins: [_.default] | ||
}); | ||
expect(code).toMatchInlineSnapshot(` | ||
"import noop from 'noop'; | ||
import { inject as _inject } from 'knifecycle'; | ||
export default _inject([\\"mysql\\", \\"?log\\"], getUser); | ||
async function getUser({ | ||
mysql: db, | ||
log = noop, | ||
...services | ||
}, { | ||
userId | ||
}) { | ||
return {}; | ||
}" | ||
`); | ||
}); | ||
it('should work with no injection', () => { | ||
var example = ` | ||
const { code } = transform(example, { | ||
plugins: [plugin], | ||
}); | ||
expect(code).toMatchInlineSnapshot(` | ||
"import noop from 'noop'; | ||
import { inject as _inject } from 'knifecycle'; | ||
export default _inject(["mysql", "?log"], getUser); | ||
async function getUser({ | ||
mysql: db, | ||
log = noop, | ||
...services | ||
}, { | ||
userId | ||
}) { | ||
return {}; | ||
}" | ||
`); | ||
}); | ||
test('should work with no injection', () => { | ||
const example = ` | ||
import noop from 'noop'; | ||
@@ -75,11 +64,9 @@ import { autoInject } from 'knifecycle'; | ||
`; | ||
const { | ||
code | ||
} = (0, _core.transform)(example, { | ||
plugins: [_.default] | ||
}); | ||
expect(code).toMatchSnapshot(); | ||
}); | ||
it('should work with several auto functions', () => { | ||
var example = ` | ||
const { code } = transform(example, { | ||
plugins: [plugin], | ||
}); | ||
expect(code).toMatchSnapshot(); | ||
}); | ||
test('should work with several auto functions', () => { | ||
const example = ` | ||
import noop from 'noop'; | ||
@@ -94,11 +81,9 @@ import { autoInject, autoName } from 'knifecycle'; | ||
`; | ||
const { | ||
code | ||
} = (0, _core.transform)(example, { | ||
plugins: [_.default] | ||
}); | ||
expect(code).toMatchSnapshot(); | ||
}); | ||
it('should work with non-destructured "_" named args', () => { | ||
var example = ` | ||
const { code } = transform(example, { | ||
plugins: [plugin], | ||
}); | ||
expect(code).toMatchSnapshot(); | ||
}); | ||
test('should work with non-destructured "_" named args', () => { | ||
const example = ` | ||
import noop from 'noop'; | ||
@@ -113,11 +98,9 @@ import { autoInject, autoName } from 'knifecycle'; | ||
`; | ||
const { | ||
code | ||
} = (0, _core.transform)(example, { | ||
plugins: [_.default] | ||
}); | ||
expect(code).toMatchSnapshot(); | ||
}); | ||
it('should fail with non-destructured arg', () => { | ||
var example = ` | ||
const { code } = transform(example, { | ||
plugins: [plugin], | ||
}); | ||
expect(code).toMatchSnapshot(); | ||
}); | ||
test('should fail with non-destructured arg', () => { | ||
const example = ` | ||
import noop from 'noop'; | ||
@@ -132,12 +115,10 @@ import { autoInject, autoName } from 'knifecycle'; | ||
`; | ||
expect(() => { | ||
(0, _core.transform)(example, { | ||
plugins: [_.default] | ||
expect(() => { | ||
transform(example, { plugins: [plugin] }); | ||
}).toThrow('Expect the dependencies to be defined through an object pattern.'); | ||
}); | ||
}).toThrow('Expect the dependencies to be defined through an object pattern.'); | ||
}); | ||
}); | ||
describe('autoName', () => { | ||
it('should work with es6 modules imports', () => { | ||
var example = ` | ||
describe('autoName', () => { | ||
test('should work with es6 modules imports', () => { | ||
const example = ` | ||
import noop from 'noop'; | ||
@@ -152,11 +133,9 @@ import { autoName } from 'knifecycle'; | ||
`; | ||
const { | ||
code | ||
} = (0, _core.transform)(example, { | ||
plugins: [_.default] | ||
}); | ||
expect(code).toMatchSnapshot(); | ||
}); | ||
it('should work with init prefix', () => { | ||
var example = ` | ||
const { code } = transform(example, { | ||
plugins: [plugin], | ||
}); | ||
expect(code).toMatchSnapshot(); | ||
}); | ||
test('should work with init prefix', () => { | ||
const example = ` | ||
import noop from 'noop'; | ||
@@ -171,13 +150,11 @@ import { autoName } from 'knifecycle'; | ||
`; | ||
const { | ||
code | ||
} = (0, _core.transform)(example, { | ||
plugins: [_.default] | ||
}); | ||
expect(code).toMatchSnapshot(); | ||
const { code } = transform(example, { | ||
plugins: [plugin], | ||
}); | ||
expect(code).toMatchSnapshot(); | ||
}); | ||
}); | ||
}); | ||
describe('autoService', () => { | ||
it('should work with es6 modules imports', () => { | ||
var example = ` | ||
describe('autoService', () => { | ||
test('should work with es6 modules imports', () => { | ||
const example = ` | ||
import noop from 'noop'; | ||
@@ -194,11 +171,9 @@ import { autoService } from 'knifecycle'; | ||
`; | ||
const { | ||
code | ||
} = (0, _core.transform)(example, { | ||
plugins: [_.default] | ||
}); | ||
expect(code).toMatchSnapshot(); | ||
}); | ||
it('should work with no dependencies', () => { | ||
var example = ` | ||
const { code } = transform(example, { | ||
plugins: [plugin], | ||
}); | ||
expect(code).toMatchSnapshot(); | ||
}); | ||
test('should work with no dependencies', () => { | ||
const example = ` | ||
import noop from 'noop'; | ||
@@ -215,13 +190,11 @@ import { autoService } from 'knifecycle'; | ||
`; | ||
const { | ||
code | ||
} = (0, _core.transform)(example, { | ||
plugins: [_.default] | ||
}); | ||
expect(code).toMatchSnapshot(); | ||
const { code } = transform(example, { | ||
plugins: [plugin], | ||
}); | ||
expect(code).toMatchSnapshot(); | ||
}); | ||
}); | ||
}); | ||
describe('autoProvider', () => { | ||
it('should work with es6 modules imports', () => { | ||
var example = ` | ||
describe('autoProvider', () => { | ||
test('should work with es6 modules imports', () => { | ||
const example = ` | ||
import noop from 'noop'; | ||
@@ -238,11 +211,9 @@ import { autoProvider } from 'knifecycle'; | ||
`; | ||
const { | ||
code | ||
} = (0, _core.transform)(example, { | ||
plugins: [_.default] | ||
}); | ||
expect(code).toMatchSnapshot(); | ||
}); | ||
it('should work with options', () => { | ||
var example = ` | ||
const { code } = transform(example, { | ||
plugins: [plugin], | ||
}); | ||
expect(code).toMatchSnapshot(); | ||
}); | ||
test('should work with options', () => { | ||
const example = ` | ||
import noop from 'noop'; | ||
@@ -259,13 +230,11 @@ import { autoProvider } from 'knifecycle'; | ||
`; | ||
const { | ||
code | ||
} = (0, _core.transform)(example, { | ||
plugins: [_.default] | ||
}); | ||
expect(code).toMatchSnapshot(); | ||
const { code } = transform(example, { | ||
plugins: [plugin], | ||
}); | ||
expect(code).toMatchSnapshot(); | ||
}); | ||
}); | ||
}); | ||
describe('autoHandler', () => { | ||
it('should work with es6 modules imports', () => { | ||
var example = ` | ||
describe('autoHandler', () => { | ||
test('should work with es6 modules imports', () => { | ||
const example = ` | ||
import noop from 'noop'; | ||
@@ -280,11 +249,9 @@ import { autoHandler } from 'knifecycle'; | ||
`; | ||
const { | ||
code | ||
} = (0, _core.transform)(example, { | ||
plugins: [_.default] | ||
}); | ||
expect(code).toMatchSnapshot(); | ||
}); | ||
it('should work with inline function expressions', () => { | ||
var example = ` | ||
const { code } = transform(example, { | ||
plugins: [plugin], | ||
}); | ||
expect(code).toMatchSnapshot(); | ||
}); | ||
test('should work with inline function expressions', () => { | ||
const example = ` | ||
import noop from 'noop'; | ||
@@ -297,11 +264,9 @@ import { autoHandler } from 'knifecycle'; | ||
`; | ||
const { | ||
code | ||
} = (0, _core.transform)(example, { | ||
plugins: [_.default] | ||
}); | ||
expect(code).toMatchSnapshot(); | ||
}); | ||
it('should work with a function inside a var', () => { | ||
var example = ` | ||
const { code } = transform(example, { | ||
plugins: [plugin], | ||
}); | ||
expect(code).toMatchSnapshot(); | ||
}); | ||
test('should work with a function inside a var', () => { | ||
const example = ` | ||
import noop from 'noop'; | ||
@@ -319,11 +284,9 @@ import { autoHandler } from 'knifecycle'; | ||
`; | ||
const { | ||
code | ||
} = (0, _core.transform)(example, { | ||
plugins: [_.default] | ||
}); | ||
expect(code).toMatchSnapshot(); | ||
}); | ||
it('should work with an anonymous function inside a var', () => { | ||
var example = ` | ||
const { code } = transform(example, { | ||
plugins: [plugin], | ||
}); | ||
expect(code).toMatchSnapshot(); | ||
}); | ||
test('should work with an anonymous function inside a var', () => { | ||
const example = ` | ||
import noop from 'noop'; | ||
@@ -341,11 +304,9 @@ import { autoHandler } from 'knifecycle'; | ||
`; | ||
const { | ||
code | ||
} = (0, _core.transform)(example, { | ||
plugins: [_.default] | ||
}); | ||
expect(code).toMatchSnapshot(); | ||
}); | ||
it('should fail with anonymous function expressions', () => { | ||
var example = ` | ||
const { code } = transform(example, { | ||
plugins: [plugin], | ||
}); | ||
expect(code).toMatchSnapshot(); | ||
}); | ||
test('should fail with anonymous function expressions', () => { | ||
const example = ` | ||
import noop from 'noop'; | ||
@@ -358,10 +319,8 @@ import { autoHandler } from 'knifecycle'; | ||
`; | ||
expect(() => { | ||
(0, _core.transform)(example, { | ||
plugins: [_.default] | ||
expect(() => { | ||
transform(example, { plugins: [plugin] }); | ||
}).toThrow('Expect autoHandler to take an async function in argument.'); | ||
}); | ||
}).toThrow('Expect autoHandler to take an async function in argument.'); | ||
}); | ||
it('should fail with something defined elsewhere', () => { | ||
var example = ` | ||
test('should fail with something defined elsewhere', () => { | ||
const example = ` | ||
import noop from 'noop'; | ||
@@ -373,10 +332,8 @@ import { autoHandler } from 'knifecycle'; | ||
`; | ||
expect(() => { | ||
(0, _core.transform)(example, { | ||
plugins: [_.default] | ||
expect(() => { | ||
transform(example, { plugins: [plugin] }); | ||
}).toThrow('Expect the function passed in autoHandler to be defined in the local file.'); | ||
}); | ||
}).toThrow('Expect the function passed in autoHandler to be defined in the local file.'); | ||
}); | ||
}); | ||
}); | ||
//# sourceMappingURL=index.test.js.map |
165
package.json
{ | ||
"name": "babel-plugin-knifecycle", | ||
"version": "5.0.3", | ||
"description": "A Babel plugin to transform Knifecycle auto* functions to their raw equivalent.", | ||
"keywords": [ | ||
"knifecycle", | ||
"injection", | ||
"dependencies", | ||
"babel-plugin" | ||
], | ||
"main": "dist/index", | ||
"metapak": { | ||
@@ -18,8 +8,8 @@ "configs": [ | ||
"eslint", | ||
"babel", | ||
"travis" | ||
"tsesm", | ||
"ghactions" | ||
], | ||
"data": { | ||
"files": "src/*.js", | ||
"testFiles": "tests/*.test.js", | ||
"files": "src/*.ts", | ||
"testFiles": "tests/*.test.ts", | ||
"bundleFiles": [ | ||
@@ -34,18 +24,28 @@ "dist", | ||
}, | ||
"name": "babel-plugin-knifecycle", | ||
"version": "5.0.4", | ||
"description": "A Babel plugin to transform Knifecycle auto* functions to their raw equivalent.", | ||
"keywords": [ | ||
"knifecycle", | ||
"injection", | ||
"dependencies", | ||
"babel-plugin" | ||
], | ||
"main": "dist/index.js", | ||
"scripts": { | ||
"build": "rimraf 'dist' && tsc --outDir dist", | ||
"changelog": "conventional-changelog -p angular -i CHANGELOG.md -s && git add CHANGELOG.md", | ||
"cli": "env NODE_ENV=${NODE_ENV:-cli}", | ||
"compile": "rimraf -f 'dist' && npm run compile:cjs && npm run compile:mjs", | ||
"compile:cjs": "babel --env-name=cjs --out-dir=dist --source-maps=true src", | ||
"compile:mjs": "babel --env-name=mjs --out-file-extension=.mjs --out-dir=dist --source-maps=true src", | ||
"cover": "npm run jest -- --coverage", | ||
"coveralls": "npm run cover && cat ./coverage/lcov.info | coveralls && rm -rf ./coverage", | ||
"cz": "env NODE_ENV=${NODE_ENV:-cli} git cz", | ||
"jest": "NODE_ENV=test jest", | ||
"lint": "eslint src/*.js", | ||
"format": "npm run prettier", | ||
"jest": "NODE_OPTIONS=--experimental-vm-modules NODE_ENV=test jest", | ||
"lint": "eslint src/*.ts", | ||
"metapak": "metapak", | ||
"precz": "npm t && npm run lint && npm run metapak -- -s && npm run compile", | ||
"prettier": "prettier --write src/*.js", | ||
"preversion": "npm t && npm run lint && npm run metapak -- -s && npm run compile", | ||
"test": "npm run jest", | ||
"precz": "npm t && npm run lint && npm run metapak -- -s && npm run build", | ||
"prettier": "prettier --write src/*.ts", | ||
"preversion": "npm t && npm run lint && npm run metapak -- -s && npm run build", | ||
"rebuild": "swc ./src -s -d dist -C jsc.target=es2022", | ||
"test": "echo \"WARNING: No tests specified\" && npm run jest", | ||
"type-check": "tsc --pretty --noEmit", | ||
"version": "npm run changelog" | ||
@@ -60,21 +60,24 @@ }, | ||
"dependencies": { | ||
"knifecycle": "^12.0.2" | ||
"knifecycle": "^17.0.3" | ||
}, | ||
"devDependencies": { | ||
"@babel/cli": "^7.17.10", | ||
"@babel/core": "^7.18.2", | ||
"@babel/eslint-parser": "^7.18.2", | ||
"@babel/plugin-proposal-object-rest-spread": "^7.18.0", | ||
"@babel/preset-env": "^7.18.2", | ||
"@babel/register": "^7.17.7", | ||
"commitizen": "^4.2.4", | ||
"conventional-changelog-cli": "^2.2.2", | ||
"coveralls": "^3.1.1", | ||
"@eslint/js": "^9.7.0", | ||
"@swc/cli": "^0.4.0", | ||
"@swc/core": "^1.6.13", | ||
"@swc/helpers": "^0.5.12", | ||
"@swc/jest": "^0.2.36", | ||
"commitizen": "^4.3.0", | ||
"conventional-changelog-cli": "^5.0.0", | ||
"cz-conventional-changelog": "^3.3.0", | ||
"eslint": "^8.16.0", | ||
"eslint-plugin-prettier": "^4.0.0", | ||
"jest": "^28.1.0", | ||
"metapak": "^4.0.3", | ||
"metapak-nfroidure": "11.2.0", | ||
"prettier": "^2.6.2" | ||
"eslint": "^9.7.0", | ||
"eslint-config-prettier": "^9.1.0", | ||
"eslint-plugin-jest": "^28.6.0", | ||
"eslint-plugin-prettier": "^5.1.3", | ||
"jest": "^29.7.0", | ||
"metapak": "^6.0.1", | ||
"metapak-nfroidure": "18.2.0", | ||
"prettier": "^3.3.3", | ||
"rimraf": "^6.0.1", | ||
"typescript": "^5.5.3", | ||
"typescript-eslint": "^7.16.0" | ||
}, | ||
@@ -87,3 +90,3 @@ "repository": { | ||
"engines": { | ||
"node": ">=12.19.0" | ||
"node": ">=20.11.1" | ||
}, | ||
@@ -108,19 +111,22 @@ "files": [ | ||
"jest", | ||
"coveralls", | ||
"@swc/jest", | ||
"eslint", | ||
"prettier", | ||
"eslint-config-prettier", | ||
"prettier", | ||
"@babel/cli", | ||
"@babel/core", | ||
"@babel/register", | ||
"@babel/preset-env", | ||
"@babel/plugin-proposal-object-rest-spread", | ||
"babel-eslint", | ||
"babel-core" | ||
"eslint-plugin-prettier", | ||
"typescript-eslint", | ||
"typescript", | ||
"rimraf", | ||
"@swc/cli", | ||
"@swc/core", | ||
"@swc/helpers" | ||
] | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/nfroidure/babel-plugin-knifecycle/issues" | ||
}, | ||
"homepage": "https://github.com/nfroidure/babel-plugin-knifecycle#readme", | ||
"jest": { | ||
"coverageReporters": [ | ||
"lcov", | ||
"html" | ||
"lcov" | ||
], | ||
@@ -132,26 +138,21 @@ "testPathIgnorePatterns": [ | ||
"<rootDir>/src" | ||
] | ||
}, | ||
"eslintConfig": { | ||
"extends": [ | ||
"eslint:recommended" | ||
], | ||
"parserOptions": { | ||
"ecmaVersion": 2018, | ||
"sourceType": "module", | ||
"modules": true | ||
"transform": { | ||
"^.+\\.tsx?$": [ | ||
"@swc/jest", | ||
{} | ||
] | ||
}, | ||
"env": { | ||
"es6": true, | ||
"node": true, | ||
"jest": true, | ||
"mocha": true | ||
"testEnvironment": "node", | ||
"moduleNameMapper": { | ||
"(.+)\\.js": "$1" | ||
}, | ||
"plugins": [ | ||
"prettier" | ||
"extensionsToTreatAsEsm": [ | ||
".ts" | ||
], | ||
"rules": { | ||
"prettier/prettier": "error" | ||
} | ||
"prettierPath": null | ||
}, | ||
"overrides": { | ||
"eslint": "^9.7.0" | ||
}, | ||
"prettier": { | ||
@@ -164,22 +165,4 @@ "semi": true, | ||
}, | ||
"babel": { | ||
"presets": [ | ||
[ | ||
"@babel/env", | ||
{ | ||
"targets": { | ||
"node": "12.19.0" | ||
} | ||
} | ||
] | ||
], | ||
"plugins": [ | ||
"@babel/plugin-proposal-object-rest-spread" | ||
] | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/nfroidure/babel-plugin-knifecycle/issues" | ||
}, | ||
"homepage": "https://github.com/nfroidure/babel-plugin-knifecycle#readme", | ||
"module": "dist/index.mjs" | ||
"type": "module", | ||
"types": "dist/index.d.ts" | ||
} |
@@ -10,5 +10,3 @@ [//]: # ( ) | ||
[![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/nfroidure/babel-plugin-knifecycle/blob/master/LICENSE) | ||
[![Build status](https://travis-ci.com/nfroidure/babel-plugin-knifecycle.svg?branch=master)](https://travis-ci.com/github/nfroidure/babel-plugin-knifecycle) | ||
[![Coverage Status](https://coveralls.io/repos/github/nfroidure/babel-plugin-knifecycle/badge.svg?branch=master)](https://coveralls.io/github/nfroidure/babel-plugin-knifecycle?branch=master) | ||
[![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/nfroidure/babel-plugin-knifecycle/blob/main/LICENSE) | ||
@@ -27,2 +25,2 @@ | ||
# License | ||
[MIT](https://github.com/nfroidure/babel-plugin-knifecycle/blob/master/LICENSE) | ||
[MIT](https://github.com/nfroidure/babel-plugin-knifecycle/blob/main/LICENSE) |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
No tests
QualityPackage does not have any tests. This is a strong signal of a poorly maintained or low quality package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Yes
56936
19
13
941
1
25
1
+ Addedknifecycle@17.1.0(transitive)
+ Addedyerror@8.0.0(transitive)
- Removedknifecycle@12.0.4(transitive)
- Removedtype-fest@2.19.0(transitive)
- Removedyerror@6.2.1(transitive)
Updatedknifecycle@^17.0.3