@embroider/macros
Advanced tools
Comparing version 1.16.3-unstable.e5ef9b9 to 1.16.3
{ | ||
"name": "@embroider/macros", | ||
"version": "1.16.3-unstable.e5ef9b9", | ||
"version": "1.16.3", | ||
"private": false, | ||
@@ -22,7 +22,3 @@ "description": "Standardized build-time macros for ember apps.", | ||
], | ||
"scripts": { | ||
"test": "jest" | ||
}, | ||
"dependencies": { | ||
"@embroider/shared-internals": "2.6.2-unstable.e5ef9b9", | ||
"assert-never": "^1.2.1", | ||
@@ -34,3 +30,4 @@ "babel-import-util": "^2.0.0", | ||
"resolve": "^1.20.0", | ||
"semver": "^7.3.2" | ||
"semver": "^7.3.2", | ||
"@embroider/shared-internals": "2.6.1" | ||
}, | ||
@@ -41,4 +38,2 @@ "devDependencies": { | ||
"@babel/traverse": "^7.14.5", | ||
"@embroider/core": "3.4.11-unstable.e5ef9b9", | ||
"@embroider/test-support": "workspace:*", | ||
"@glint/template": "^1.0.0", | ||
@@ -55,4 +50,6 @@ "@types/babel__core": "^7.1.14", | ||
"code-equality-assertions": "^0.9.0", | ||
"scenario-tester": "^3.0.1", | ||
"typescript": "^5.4.5" | ||
"scenario-tester": "^2.1.2", | ||
"typescript": "^5.1.6", | ||
"@embroider/core": "3.4.11", | ||
"@embroider/test-support": "0.36.0" | ||
}, | ||
@@ -72,3 +69,6 @@ "peerDependencies": { | ||
"main": "src/ember-addon-main.js" | ||
}, | ||
"scripts": { | ||
"test": "jest" | ||
} | ||
} | ||
} |
@@ -236,4 +236,4 @@ # @embroider/macros | ||
- [ember-exam](https://github.com/ember-cli/ember-exam) | ||
- [ember-bootstrap](https://github.com/kaliber5/ember-bootstrap) | ||
- [liquid-fire](https://github.com/ember-animation/liquid-fire) | ||
- [ember-qunit](https://github.com/emberjs/ember-qunit/) | ||
- [ember-stargate](https://github.com/kaliber5/ember-stargate) |
@@ -9,3 +9,2 @@ "use strict"; | ||
const error_1 = __importDefault(require("./error")); | ||
const cloneDeep_1 = __importDefault(require("lodash/cloneDeep")); | ||
function isEachPath(path) { | ||
@@ -52,3 +51,3 @@ let right = path.get('right'); | ||
} | ||
path.insertBefore((0, cloneDeep_1.default)(path.get('body').node)); | ||
path.insertBefore(state.cloneDeep(path.get('body').node)); | ||
} | ||
@@ -55,0 +54,0 @@ path.remove(); |
@@ -36,4 +36,2 @@ "use strict"; | ||
const evaluate_json_1 = require("./evaluate-json"); | ||
const fs_1 = require("fs"); | ||
const path_1 = require("path"); | ||
function main(context) { | ||
@@ -143,47 +141,20 @@ let t = context.types; | ||
if (callee.referencesImport('@embroider/macros', 'importSync')) { | ||
let specifier = path.node.arguments[0]; | ||
if ((specifier === null || specifier === void 0 ? void 0 : specifier.type) !== 'StringLiteral') { | ||
let relativePath = ''; | ||
let property; | ||
if (specifier.type === 'TemplateLiteral') { | ||
relativePath = specifier.quasis[0].value.cooked; | ||
property = specifier.expressions[0]; | ||
if (state.opts.importSyncImplementation === 'eager') { | ||
let specifier = path.node.arguments[0]; | ||
if ((specifier === null || specifier === void 0 ? void 0 : specifier.type) !== 'StringLiteral') { | ||
throw new Error(`importSync eager mode doesn't implement non string literal arguments yet`); | ||
} | ||
// babel might transform template form `../my-path/${id}` to '../my-path/'.concat(id) | ||
if (specifier.type === 'CallExpression' && | ||
specifier.callee.type === 'MemberExpression' && | ||
specifier.callee.property.type === 'Identifier' && | ||
specifier.callee.property.name === 'concat' && | ||
specifier.callee.object.type === 'StringLiteral') { | ||
relativePath = specifier.callee.object.value; | ||
property = specifier.arguments[0]; | ||
path.replaceWith(state.importUtil.import(path, specifier.value, '*')); | ||
state.calledIdentifiers.add(callee.node); | ||
} | ||
else { | ||
if (path.scope.hasBinding('require')) { | ||
path.scope.rename('require'); | ||
} | ||
if (property && relativePath && relativePath.startsWith('.')) { | ||
const resolvedPath = (0, path_1.resolve)((0, path_1.dirname)(state.filename), relativePath); | ||
let entries = []; | ||
if ((0, fs_1.existsSync)(resolvedPath)) { | ||
entries = (0, fs_1.readdirSync)(resolvedPath).filter(e => !e.startsWith('.')); | ||
} | ||
const obj = t.objectExpression(entries.map(e => { | ||
let key = e.split('.')[0]; | ||
const rest = e.split('.').slice(1, -1); | ||
if (rest.length) { | ||
key += `.${rest}`; | ||
} | ||
const id = t.callExpression(state.importUtil.import(path, state.pathToOurAddon('es-compat2'), 'default', 'esc'), [state.importUtil.import(path, (0, path_1.join)(relativePath, key).replace(/\\/g, '/'), '*')]); | ||
return t.objectProperty(t.stringLiteral(key), id); | ||
})); | ||
const memberExpr = t.memberExpression(obj, property, true); | ||
path.replaceWith(memberExpr); | ||
state.calledIdentifiers.add(callee.node); | ||
return; | ||
} | ||
else { | ||
throw new Error(`importSync eager mode only supports dynamic paths which are relative, must start with a '.', had ${specifier.type}`); | ||
} | ||
let r = t.identifier('require'); | ||
state.generatedRequires.add(r); | ||
path.replaceWith(t.callExpression(state.importUtil.import(path, state.pathToOurAddon('es-compat2'), 'default', 'esc'), [ | ||
t.callExpression(r, path.node.arguments), | ||
])); | ||
} | ||
path.replaceWith(t.callExpression(state.importUtil.import(path, state.pathToOurAddon('es-compat2'), 'default', 'esc'), [ | ||
state.importUtil.import(path, specifier.value, '*'), | ||
])); | ||
state.calledIdentifiers.add(callee.node); | ||
return; | ||
@@ -228,6 +199,7 @@ } | ||
} | ||
if (state.opts.hideRequires && | ||
if (state.opts.importSyncImplementation === 'cjs' && | ||
path.node.name === 'require' && | ||
!state.generatedRequires.has(path.node) && | ||
!path.scope.hasBinding('require') && | ||
state.owningPackage().isEmberAddon()) { | ||
state.owningPackage().isEmberPackage()) { | ||
// Our importSync macro has been compiled to `require`. But we want to | ||
@@ -234,0 +206,0 @@ // distinguish that from any pre-existing, user-written `require` in an |
@@ -8,2 +8,3 @@ import type { NodePath, Node } from '@babel/traverse'; | ||
importUtil: ImportUtil; | ||
generatedRequires: Set<Node>; | ||
removed: Set<Node>; | ||
@@ -17,2 +18,3 @@ calledIdentifiers: Set<Node>; | ||
originalOwningPackage(): Package; | ||
cloneDeep(node: Node): Node; | ||
opts: { | ||
@@ -29,6 +31,6 @@ userConfigs: { | ||
embroiderMacrosConfigMarker: true; | ||
hideRequires: boolean; | ||
mode: 'compile-time' | 'run-time'; | ||
importSyncImplementation: 'cjs' | 'eager'; | ||
}; | ||
} | ||
export declare function initState(t: typeof Babel.types, path: NodePath<Babel.types.Program>, state: State): void; |
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.initState = void 0; | ||
const cloneDeepWith_1 = __importDefault(require("lodash/cloneDeepWith")); | ||
const cloneDeep_1 = __importDefault(require("lodash/cloneDeep")); | ||
const path_1 = require("path"); | ||
@@ -9,2 +14,3 @@ const shared_internals_1 = require("@embroider/shared-internals"); | ||
state.importUtil = new babel_import_util_1.ImportUtil(t, path); | ||
state.generatedRequires = new Set(); | ||
state.jobs = []; | ||
@@ -18,2 +24,3 @@ state.removed = new Set(); | ||
state.originalOwningPackage = originalOwningPackage; | ||
state.cloneDeep = cloneDeep; | ||
} | ||
@@ -50,2 +57,12 @@ exports.initState = initState; | ||
} | ||
function cloneDeep(node) { | ||
let state = this; | ||
return (0, cloneDeepWith_1.default)(node, function (value) { | ||
if (state.generatedRequires.has(value)) { | ||
let cloned = (0, cloneDeep_1.default)(value); | ||
state.generatedRequires.add(cloned); | ||
return cloned; | ||
} | ||
}); | ||
} | ||
//# sourceMappingURL=state.js.map |
@@ -27,6 +27,18 @@ export interface BuildPluginParams { | ||
visitor: { | ||
Program: { | ||
enter(node: any): void; | ||
exit(node: any): void; | ||
SubExpression(node: any, walker: { | ||
parent: { | ||
node: any; | ||
}; | ||
}): any; | ||
MustacheStatement(node: any): any; | ||
Template: { | ||
enter: (node: any) => void; | ||
exit: (node: any) => void; | ||
}; | ||
Block: { | ||
enter: (node: any) => void; | ||
exit: (node: any) => void; | ||
}; | ||
Program?: undefined; | ||
} | { | ||
SubExpression(node: any, walker: { | ||
@@ -38,2 +50,8 @@ parent: { | ||
MustacheStatement(node: any): any; | ||
Program: { | ||
enter: (node: any) => void; | ||
exit: (node: any) => void; | ||
}; | ||
Template?: undefined; | ||
Block?: undefined; | ||
}; | ||
@@ -54,6 +72,18 @@ }; | ||
visitor: { | ||
Program: { | ||
enter(node: any): void; | ||
exit(node: any): void; | ||
SubExpression(node: any, walker: { | ||
parent: { | ||
node: any; | ||
}; | ||
}): any; | ||
MustacheStatement(node: any): any; | ||
Template: { | ||
enter: (node: any) => void; | ||
exit: (node: any) => void; | ||
}; | ||
Block: { | ||
enter: (node: any) => void; | ||
exit: (node: any) => void; | ||
}; | ||
Program?: undefined; | ||
} | { | ||
SubExpression(node: any, walker: { | ||
@@ -65,2 +95,8 @@ parent: { | ||
MustacheStatement(node: any): any; | ||
Program: { | ||
enter: (node: any) => void; | ||
exit: (node: any) => void; | ||
}; | ||
Template?: undefined; | ||
Block?: undefined; | ||
}; | ||
@@ -75,6 +111,16 @@ }; | ||
visitor: { | ||
Program: { | ||
enter(node: any): void; | ||
exit(node: any): void; | ||
BlockStatement(node: any): any; | ||
SubExpression(node: any): any; | ||
ElementNode(node: any): void; | ||
MustacheStatement(node: any): any; | ||
Template: { | ||
enter: (node: any) => void; | ||
exit: (node: any) => void; | ||
}; | ||
Block: { | ||
enter: (node: any) => void; | ||
exit: (node: any) => void; | ||
}; | ||
Program?: undefined; | ||
} | { | ||
BlockStatement(node: any): any; | ||
@@ -84,3 +130,9 @@ SubExpression(node: any): any; | ||
MustacheStatement(node: any): any; | ||
Program: { | ||
enter: (node: any) => void; | ||
exit: (node: any) => void; | ||
}; | ||
Template?: undefined; | ||
Block?: undefined; | ||
}; | ||
}; |
@@ -37,14 +37,3 @@ "use strict"; | ||
visitor: { | ||
Program: { | ||
enter(node) { | ||
if (node.blockParams.length > 0) { | ||
scopeStack.push(node.blockParams); | ||
} | ||
}, | ||
exit(node) { | ||
if (node.blockParams.length > 0) { | ||
scopeStack.pop(); | ||
} | ||
}, | ||
}, | ||
...scopeVisitors(env, scopeStack), | ||
SubExpression(node, walker) { | ||
@@ -54,3 +43,3 @@ if (node.path.type !== 'PathExpression') { | ||
} | ||
if (inScope(scopeStack, node.path.parts[0])) { | ||
if (inScope(scopeStack, headOf(node.path))) { | ||
return; | ||
@@ -78,3 +67,3 @@ } | ||
} | ||
if (inScope(scopeStack, node.path.parts[0])) { | ||
if (inScope(scopeStack, headOf(node.path))) { | ||
return; | ||
@@ -112,14 +101,3 @@ } | ||
visitor: { | ||
Program: { | ||
enter(node) { | ||
if (node.blockParams.length > 0) { | ||
scopeStack.push(node.blockParams); | ||
} | ||
}, | ||
exit(node) { | ||
if (node.blockParams.length > 0) { | ||
scopeStack.pop(); | ||
} | ||
}, | ||
}, | ||
...scopeVisitors(env, scopeStack), | ||
BlockStatement(node) { | ||
@@ -129,3 +107,3 @@ if (node.path.type !== 'PathExpression') { | ||
} | ||
if (inScope(scopeStack, node.path.parts[0])) { | ||
if (inScope(scopeStack, headOf(node.path))) { | ||
return; | ||
@@ -144,3 +122,3 @@ } | ||
} | ||
if (inScope(scopeStack, node.path.parts[0])) { | ||
if (inScope(scopeStack, headOf(node.path))) { | ||
return; | ||
@@ -173,3 +151,3 @@ } | ||
if (modifier.path.type === 'UndefinedLiteral') { | ||
return true; | ||
return false; | ||
} | ||
@@ -180,3 +158,3 @@ } | ||
} | ||
if (inScope(scopeStack, modifier.path.parts[0])) { | ||
if (inScope(scopeStack, headOf(node.path))) { | ||
return true; | ||
@@ -196,3 +174,3 @@ } | ||
} | ||
if (inScope(scopeStack, node.path.parts[0])) { | ||
if (inScope(scopeStack, headOf(node.path))) { | ||
return; | ||
@@ -230,2 +208,31 @@ } | ||
} | ||
function headOf(path) { | ||
if (!path) | ||
return; | ||
return 'head' in path ? path.head.name : path.parts[0]; | ||
} | ||
function scopeVisitors(env, scopeStack) { | ||
function enter(node) { | ||
if (node.blockParams.length > 0) { | ||
scopeStack.push(node.blockParams); | ||
} | ||
} | ||
function exit(node) { | ||
if (node.blockParams.length > 0) { | ||
scopeStack.pop(); | ||
} | ||
} | ||
let hasTemplate = 'template' in env.syntax.builders; | ||
if (hasTemplate) { | ||
return { | ||
Template: { enter, exit }, | ||
Block: { enter, exit }, | ||
}; | ||
} | ||
else { | ||
return { | ||
Program: { enter, exit }, | ||
}; | ||
} | ||
} | ||
//# sourceMappingURL=ast-transform.js.map |
@@ -19,2 +19,5 @@ import type { PluginItem } from '@babel/core'; | ||
enablePackageDevelopment(packageRoot: string): void; | ||
private _importSyncImplementation; | ||
get importSyncImplementation(): 'cjs' | 'eager'; | ||
set importSyncImplementation(value: 'cjs' | 'eager'); | ||
private constructor(); | ||
@@ -21,0 +24,0 @@ private get packageCache(); |
@@ -94,2 +94,11 @@ "use strict"; | ||
} | ||
get importSyncImplementation() { | ||
return this._importSyncImplementation; | ||
} | ||
set importSyncImplementation(value) { | ||
if (!this._configWritable) { | ||
throw new Error(`[Embroider:MacrosConfig] attempted to set importSyncImplementation after configs have been finalized`); | ||
} | ||
this._importSyncImplementation = value; | ||
} | ||
constructor(origAppRoot) { | ||
@@ -100,2 +109,3 @@ this.origAppRoot = origAppRoot; | ||
this.isDevelopingPackageRoots = new Set(); | ||
this._importSyncImplementation = 'cjs'; | ||
this._configWritable = true; | ||
@@ -259,3 +269,3 @@ this.configs = new Map(); | ||
}, | ||
hideRequires: true, | ||
importSyncImplementation: this.importSyncImplementation, | ||
}; | ||
@@ -262,0 +272,0 @@ let lockFilePath = find_up_1.default.sync(['yarn.lock', 'package-lock.json', 'pnpm-lock.yaml'], { cwd: self.appRoot }); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
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
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
72
2618
1
1
275718
+ Added@embroider/shared-internals@2.6.1(transitive)
- Removed@embroider/shared-internals@2.6.2-unstable.e5ef9b9(transitive)