@mattsjones/css-babel-plugin
Advanced tools
Comparing version 0.0.2 to 0.0.3
@@ -13,2 +13,3 @@ import { PluginObj, PluginPass } from '@babel/core'; | ||
alias?: string; | ||
projectRoot?: string; | ||
} | ||
@@ -19,4 +20,6 @@ declare type Context = PluginPass & { | ||
importIdentifiers: Map<string, RelevantExport>; | ||
packageIdentifier: string; | ||
fileScope: string; | ||
}; | ||
export default function (): PluginObj<Context>; | ||
export {}; |
@@ -5,4 +5,14 @@ 'use strict'; | ||
var path = require('path'); | ||
var core = require('@babel/core'); | ||
var template = require('@babel/template'); | ||
function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; } | ||
var template__default = /*#__PURE__*/_interopDefault(template); | ||
const buildSetFileScope = template__default['default'](` | ||
import { setFileScope, endFileScope } from %%packageIdentifier%% | ||
setFileScope(%%fileScope%%) | ||
`); | ||
const exportConfig = { | ||
@@ -77,4 +87,6 @@ style: { | ||
return { | ||
pre() { | ||
var _this$opts; | ||
pre({ | ||
opts | ||
}) { | ||
var _this$opts, _this$opts2; | ||
@@ -84,5 +96,32 @@ this.importIdentifiers = new Map(); | ||
this.packageIdentifier = ((_this$opts = this.opts) === null || _this$opts === void 0 ? void 0 : _this$opts.alias) || '@mattsjones/css-core'; | ||
const projectRoot = ((_this$opts2 = this.opts) === null || _this$opts2 === void 0 ? void 0 : _this$opts2.projectRoot) || opts.root; | ||
if (!projectRoot) { | ||
// TODO Make error better | ||
throw new Error('Project root must be specified'); | ||
} | ||
if (!opts.filename) { | ||
// TODO Make error better | ||
throw new Error('Filename must be available'); | ||
} | ||
this.fileScope = path.relative(projectRoot, opts.filename); | ||
}, | ||
visitor: { | ||
Program: { | ||
exit(path) { | ||
if (this.importIdentifiers.size > 0 || this.namespaceImport) { | ||
// Wrap module with file scope calls | ||
path.unshiftContainer('body', buildSetFileScope({ | ||
packageIdentifier: core.types.stringLiteral(`${this.packageIdentifier}/fileScope`), | ||
fileScope: core.types.stringLiteral(this.fileScope) | ||
})); | ||
path.pushContainer('body', core.types.callExpression(core.types.identifier('endFileScope'), [])); | ||
} | ||
} | ||
}, | ||
ImportDeclaration(path) { | ||
@@ -89,0 +128,0 @@ if (path.node.source.value === this.packageIdentifier) { |
@@ -5,4 +5,14 @@ 'use strict'; | ||
var path = require('path'); | ||
var core = require('@babel/core'); | ||
var template = require('@babel/template'); | ||
function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; } | ||
var template__default = /*#__PURE__*/_interopDefault(template); | ||
const buildSetFileScope = template__default['default'](` | ||
import { setFileScope, endFileScope } from %%packageIdentifier%% | ||
setFileScope(%%fileScope%%) | ||
`); | ||
const exportConfig = { | ||
@@ -77,4 +87,6 @@ style: { | ||
return { | ||
pre() { | ||
var _this$opts; | ||
pre({ | ||
opts | ||
}) { | ||
var _this$opts, _this$opts2; | ||
@@ -84,5 +96,32 @@ this.importIdentifiers = new Map(); | ||
this.packageIdentifier = ((_this$opts = this.opts) === null || _this$opts === void 0 ? void 0 : _this$opts.alias) || '@mattsjones/css-core'; | ||
const projectRoot = ((_this$opts2 = this.opts) === null || _this$opts2 === void 0 ? void 0 : _this$opts2.projectRoot) || opts.root; | ||
if (!projectRoot) { | ||
// TODO Make error better | ||
throw new Error('Project root must be specified'); | ||
} | ||
if (!opts.filename) { | ||
// TODO Make error better | ||
throw new Error('Filename must be available'); | ||
} | ||
this.fileScope = path.relative(projectRoot, opts.filename); | ||
}, | ||
visitor: { | ||
Program: { | ||
exit(path) { | ||
if (this.importIdentifiers.size > 0 || this.namespaceImport) { | ||
// Wrap module with file scope calls | ||
path.unshiftContainer('body', buildSetFileScope({ | ||
packageIdentifier: core.types.stringLiteral(`${this.packageIdentifier}/fileScope`), | ||
fileScope: core.types.stringLiteral(this.fileScope) | ||
})); | ||
path.pushContainer('body', core.types.callExpression(core.types.identifier('endFileScope'), [])); | ||
} | ||
} | ||
}, | ||
ImportDeclaration(path) { | ||
@@ -89,0 +128,0 @@ if (path.node.source.value === this.packageIdentifier) { |
@@ -0,3 +1,9 @@ | ||
import { relative } from 'path'; | ||
import { types } from '@babel/core'; | ||
import template from '@babel/template'; | ||
const buildSetFileScope = template(` | ||
import { setFileScope, endFileScope } from %%packageIdentifier%% | ||
setFileScope(%%fileScope%%) | ||
`); | ||
const exportConfig = { | ||
@@ -72,4 +78,6 @@ style: { | ||
return { | ||
pre() { | ||
var _this$opts; | ||
pre({ | ||
opts | ||
}) { | ||
var _this$opts, _this$opts2; | ||
@@ -79,5 +87,32 @@ this.importIdentifiers = new Map(); | ||
this.packageIdentifier = ((_this$opts = this.opts) === null || _this$opts === void 0 ? void 0 : _this$opts.alias) || '@mattsjones/css-core'; | ||
const projectRoot = ((_this$opts2 = this.opts) === null || _this$opts2 === void 0 ? void 0 : _this$opts2.projectRoot) || opts.root; | ||
if (!projectRoot) { | ||
// TODO Make error better | ||
throw new Error('Project root must be specified'); | ||
} | ||
if (!opts.filename) { | ||
// TODO Make error better | ||
throw new Error('Filename must be available'); | ||
} | ||
this.fileScope = relative(projectRoot, opts.filename); | ||
}, | ||
visitor: { | ||
Program: { | ||
exit(path) { | ||
if (this.importIdentifiers.size > 0 || this.namespaceImport) { | ||
// Wrap module with file scope calls | ||
path.unshiftContainer('body', buildSetFileScope({ | ||
packageIdentifier: types.stringLiteral(`${this.packageIdentifier}/fileScope`), | ||
fileScope: types.stringLiteral(this.fileScope) | ||
})); | ||
path.pushContainer('body', types.callExpression(types.identifier('endFileScope'), [])); | ||
} | ||
} | ||
}, | ||
ImportDeclaration(path) { | ||
@@ -84,0 +119,0 @@ if (path.node.source.value === this.packageIdentifier) { |
{ | ||
"name": "@mattsjones/css-babel-plugin", | ||
"version": "0.0.2", | ||
"version": "0.0.3", | ||
"main": "dist/mattsjones-css-babel-plugin.cjs.js", | ||
@@ -17,5 +17,6 @@ "module": "dist/mattsjones-css-babel-plugin.esm.js", | ||
"dependencies": { | ||
"@babel/core": "^7.12.10" | ||
"@babel/core": "^7.12.10", | ||
"@babel/template": "^7.12.13" | ||
}, | ||
"devDependencies": {} | ||
} |
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
15292
438
0
2
+ Added@babel/template@^7.12.13
+ Added@babel/core@7.26.7(transitive)
+ Added@babel/helpers@7.26.7(transitive)
+ Added@babel/parser@7.26.7(transitive)
+ Added@babel/traverse@7.26.7(transitive)
+ Added@babel/types@7.26.7(transitive)
+ Addedcaniuse-lite@1.0.30001696(transitive)
+ Addedelectron-to-chromium@1.5.90(transitive)
- Removed@babel/core@7.26.0(transitive)
- Removed@babel/helpers@7.26.0(transitive)
- Removed@babel/parser@7.26.5(transitive)
- Removed@babel/traverse@7.26.5(transitive)
- Removed@babel/types@7.26.5(transitive)
- Removedcaniuse-lite@1.0.30001695(transitive)
- Removedelectron-to-chromium@1.5.86(transitive)