Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@linaria/shaker

Package Overview
Dependencies
Maintainers
4
Versions
49
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@linaria/shaker - npm Package Compare versions

Comparing version 3.0.0-beta.22 to 4.0.0-beta.0

esm/plugins/__tests__/shaker-plugin.test.js

62

esm/index.js
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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc