@linaria/shaker
Advanced tools
Comparing version 3.0.0-beta.22 to 4.0.0-beta.0
import { transformSync } from '@babel/core'; | ||
import generator from '@babel/generator'; | ||
import { buildOptions } from '@linaria/babel-preset'; | ||
import { debug } from '@linaria/logger'; | ||
import shake from './shaker'; | ||
export { default as buildDepsGraph } from './graphBuilder'; | ||
import { buildOptions, loadBabelOptions } from '@linaria/utils'; | ||
import { hasShakerMetadata } from './plugins/shaker-plugin'; | ||
export { default as shakerPlugin } from './plugins/shaker-plugin'; | ||
const configCache = new Map(); | ||
function prepareForShake(filename, options, code) { | ||
const transformOptions = buildOptions(filename, options); | ||
transformOptions.ast = true; | ||
transformOptions.presets.unshift([require.resolve('@babel/preset-env'), { | ||
targets: 'ie 11' | ||
}]); | ||
transformOptions.presets.unshift([require.resolve('@linaria/preeval'), options]); | ||
transformOptions.plugins.unshift(require.resolve('babel-plugin-transform-react-remove-prop-types')); | ||
transformOptions.plugins.unshift([require.resolve('@babel/plugin-transform-runtime'), { | ||
useESModules: false | ||
}]); | ||
debug('evaluator:shaker:transform', `Transform ${filename} with options ${JSON.stringify(transformOptions, null, 2)}`); | ||
const transformed = transformSync(code, transformOptions); | ||
const getShakerConfig = only => { | ||
const sortedOnly = [...(only ?? [])]; | ||
sortedOnly.sort(); | ||
const key = sortedOnly.join('\0'); | ||
if (transformed === null || !transformed.ast) { | ||
throw new Error(`${filename} cannot be transformed`); | ||
if (configCache.has(key)) { | ||
return configCache.get(key); | ||
} | ||
return transformed.ast.program; | ||
} | ||
const config = { | ||
ast: true, | ||
envName: 'linaria', | ||
targets: { | ||
node: 'current', | ||
esmodules: false | ||
}, | ||
plugins: [[require.resolve('./plugins/shaker-plugin'), { | ||
onlyExports: sortedOnly | ||
}], require.resolve('@babel/plugin-transform-modules-commonjs')] | ||
}; | ||
configCache.set(key, config); | ||
return config; | ||
}; | ||
const shaker = (filename, options, text, only = null) => { | ||
const [shaken, imports] = shake(prepareForShake(filename, options, text), only); | ||
debug('evaluator:shaker:generate', `Generate shaken source code ${filename}`); | ||
const { | ||
code: shakenCode | ||
} = generator(shaken); | ||
return [shakenCode, imports]; | ||
const transformOptions = loadBabelOptions(filename, buildOptions(options?.babelOptions, getShakerConfig(only))); | ||
const transformed = transformSync(text, { ...transformOptions, | ||
filename | ||
}); | ||
if (!transformed || !hasShakerMetadata(transformed.metadata)) { | ||
throw new Error(`${filename} has no shaker metadata`); | ||
} | ||
return [transformed.code ?? '', transformed.metadata.__linariaShaker.imports]; | ||
}; | ||
@@ -37,0 +43,0 @@ |
@@ -6,52 +6,59 @@ "use strict"; | ||
}); | ||
Object.defineProperty(exports, "buildDepsGraph", { | ||
exports.default = void 0; | ||
Object.defineProperty(exports, "shakerPlugin", { | ||
enumerable: true, | ||
get: function () { | ||
return _graphBuilder.default; | ||
return _shakerPlugin.default; | ||
} | ||
}); | ||
exports.default = void 0; | ||
var _core = require("@babel/core"); | ||
var _generator = _interopRequireDefault(require("@babel/generator")); | ||
var _utils = require("@linaria/utils"); | ||
var _babelPreset = require("@linaria/babel-preset"); | ||
var _shakerPlugin = _interopRequireWildcard(require("./plugins/shaker-plugin")); | ||
var _logger = require("@linaria/logger"); | ||
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); } | ||
var _shaker = _interopRequireDefault(require("./shaker")); | ||
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; } | ||
var _graphBuilder = _interopRequireDefault(require("./graphBuilder")); | ||
const configCache = new Map(); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
const getShakerConfig = only => { | ||
const sortedOnly = [...(only !== null && only !== void 0 ? only : [])]; | ||
sortedOnly.sort(); | ||
const key = sortedOnly.join('\0'); | ||
function prepareForShake(filename, options, code) { | ||
const transformOptions = (0, _babelPreset.buildOptions)(filename, options); | ||
transformOptions.ast = true; | ||
transformOptions.presets.unshift([require.resolve('@babel/preset-env'), { | ||
targets: 'ie 11' | ||
}]); | ||
transformOptions.presets.unshift([require.resolve('@linaria/preeval'), options]); | ||
transformOptions.plugins.unshift(require.resolve('babel-plugin-transform-react-remove-prop-types')); | ||
transformOptions.plugins.unshift([require.resolve('@babel/plugin-transform-runtime'), { | ||
useESModules: false | ||
}]); | ||
(0, _logger.debug)('evaluator:shaker:transform', `Transform ${filename} with options ${JSON.stringify(transformOptions, null, 2)}`); | ||
const transformed = (0, _core.transformSync)(code, transformOptions); | ||
if (transformed === null || !transformed.ast) { | ||
throw new Error(`${filename} cannot be transformed`); | ||
if (configCache.has(key)) { | ||
return configCache.get(key); | ||
} | ||
return transformed.ast.program; | ||
} | ||
const config = { | ||
ast: true, | ||
envName: 'linaria', | ||
targets: { | ||
node: 'current', | ||
esmodules: false | ||
}, | ||
plugins: [[require.resolve('./plugins/shaker-plugin'), { | ||
onlyExports: sortedOnly | ||
}], require.resolve('@babel/plugin-transform-modules-commonjs')] | ||
}; | ||
configCache.set(key, config); | ||
return config; | ||
}; | ||
const shaker = (filename, options, text, only = null) => { | ||
const [shaken, imports] = (0, _shaker.default)(prepareForShake(filename, options, text), only); | ||
(0, _logger.debug)('evaluator:shaker:generate', `Generate shaken source code ${filename}`); | ||
const { | ||
code: shakenCode | ||
} = (0, _generator.default)(shaken); | ||
return [shakenCode, imports]; | ||
var _transformed$code; | ||
const transformOptions = (0, _utils.loadBabelOptions)(filename, (0, _utils.buildOptions)(options === null || options === void 0 ? void 0 : options.babelOptions, getShakerConfig(only))); | ||
const transformed = (0, _core.transformSync)(text, { ...transformOptions, | ||
filename | ||
}); | ||
if (!transformed || !(0, _shakerPlugin.hasShakerMetadata)(transformed.metadata)) { | ||
throw new Error(`${filename} has no shaker metadata`); | ||
} | ||
return [(_transformed$code = transformed.code) !== null && _transformed$code !== void 0 ? _transformed$code : '', transformed.metadata.__linariaShaker.imports]; | ||
}; | ||
@@ -58,0 +65,0 @@ |
{ | ||
"name": "@linaria/shaker", | ||
"description": "Blazing fast zero-runtime CSS in JS library", | ||
"version": "3.0.0-beta.22", | ||
"version": "4.0.0-beta.0", | ||
"bugs": "https://github.com/callstack/linaria/issues", | ||
@@ -9,8 +9,8 @@ "dependencies": { | ||
"@babel/generator": ">=7", | ||
"@babel/plugin-transform-modules-commonjs": "^7.18.2", | ||
"@babel/plugin-transform-runtime": ">=7", | ||
"@babel/plugin-transform-template-literals": ">=7", | ||
"@babel/preset-env": ">=7", | ||
"@linaria/babel-preset": "^3.0.0-beta.22", | ||
"@linaria/logger": "^3.0.0-beta.20", | ||
"@linaria/preeval": "^3.0.0-beta.22", | ||
"@linaria/logger": "^4.0.0-beta.0", | ||
"@linaria/utils": "^4.0.0-beta.0", | ||
"babel-plugin-transform-react-remove-prop-types": "^0.4.24", | ||
@@ -23,3 +23,10 @@ "ts-invariant": "^0.10.3" | ||
"@types/babel__generator": "^7.6.4", | ||
"@types/babel__traverse": "^7.17.1" | ||
"@types/babel__traverse": "^7.17.1", | ||
"@types/dedent": "^0.7.0", | ||
"@types/jest": "^28.1.0", | ||
"@types/node": "^17.0.39", | ||
"dedent": "^0.7.0", | ||
"jest": "^28.1.0", | ||
"ts-jest": "^28.0.4", | ||
"typescript": "^4.7.3" | ||
}, | ||
@@ -26,0 +33,0 @@ "engines": { |
@@ -1,4 +0,4 @@ | ||
import type { Evaluator } from '@linaria/babel-preset'; | ||
export { default as buildDepsGraph } from './graphBuilder'; | ||
import type { Evaluator } from '@linaria/utils'; | ||
export { default as shakerPlugin } from './plugins/shaker-plugin'; | ||
declare const shaker: Evaluator; | ||
export default shaker; |
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
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
95575
11
28
873
1
+ Added@linaria/utils@^4.0.0-beta.0
+ Added@linaria/logger@4.5.0(transitive)
+ Added@linaria/utils@4.5.3(transitive)
+ Addedbabel-merge@3.0.0(transitive)
+ Addedbalanced-match@1.0.2(transitive)
+ Addedbrace-expansion@2.0.1(transitive)
+ Addeddeepmerge@2.2.1(transitive)
+ Addedis-extendable@1.0.1(transitive)
+ Addedis-plain-object@2.0.4(transitive)
+ Addedisobject@3.0.1(transitive)
+ Addedminimatch@9.0.5(transitive)
+ Addedobject.omit@3.0.0(transitive)
- Removed@linaria/babel-preset@^3.0.0-beta.22
- Removed@linaria/preeval@^3.0.0-beta.22
- Removed@linaria/babel-preset@3.0.0-beta.24(transitive)
- Removed@linaria/core@3.0.0-beta.22(transitive)
- Removed@linaria/logger@3.0.0-beta.20(transitive)
- Removed@linaria/preeval@3.0.0-beta.23(transitive)
- Removed@linaria/utils@3.0.0-beta.20(transitive)
- Removedargparse@1.0.10(transitive)
- Removedcaller-callsite@2.0.0(transitive)
- Removedcaller-path@2.0.0(transitive)
- Removedcallsites@2.0.0(transitive)
- Removedcosmiconfig@5.2.1(transitive)
- Removederror-ex@1.3.2(transitive)
- Removedesprima@4.0.1(transitive)
- Removedimport-fresh@2.0.0(transitive)
- Removedis-arrayish@0.2.1(transitive)
- Removedis-directory@0.3.1(transitive)
- Removedjs-yaml@3.14.1(transitive)
- Removedjson-parse-better-errors@1.0.2(transitive)
- Removedparse-json@4.0.0(transitive)
- Removedresolve-from@3.0.0(transitive)
- Removedsource-map@0.7.4(transitive)
- Removedsprintf-js@1.0.3(transitive)
- Removedstylis@3.5.4(transitive)