Skip to content

Commit

Permalink
feat: get rid of Linaria
Browse files Browse the repository at this point in the history
  • Loading branch information
Anber committed Nov 30, 2023
1 parent 0871602 commit 2fc6fd9
Show file tree
Hide file tree
Showing 36 changed files with 1,187 additions and 737 deletions.
10 changes: 5 additions & 5 deletions examples/object-syntax/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
"@wyw-in-js/processor-utils": "workspace:*"
},
"devDependencies": {
"@babel/core": "^7.23.0",
"@babel/traverse": "^7.23.0",
"@babel/types": "^7.23.0",
"@types/babel__core": "^7.20.2",
"@types/babel__traverse": "^7.20.2",
"@babel/core": "^7.23.5",
"@babel/traverse": "^7.23.5",
"@babel/types": "^7.23.5",
"@types/babel__core": "^7.20.5",
"@types/babel__traverse": "^7.20.4",
"@types/node": "^16.18.55",
"@wyw-in-js/babel-config": "workspace:*",
"@wyw-in-js/eslint-config": "workspace:*",
Expand Down
10 changes: 5 additions & 5 deletions examples/template-tag-syntax/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
"@wyw-in-js/processor-utils": "workspace:*"
},
"devDependencies": {
"@babel/core": "^7.23.0",
"@babel/traverse": "^7.23.0",
"@babel/types": "^7.23.0",
"@types/babel__core": "^7.20.2",
"@types/babel__traverse": "^7.20.2",
"@babel/core": "^7.23.5",
"@babel/traverse": "^7.23.5",
"@babel/types": "^7.23.5",
"@types/babel__core": "^7.20.5",
"@types/babel__traverse": "^7.20.4",
"@types/node": "^16.18.55",
"@wyw-in-js/babel-config": "workspace:*",
"@wyw-in-js/eslint-config": "workspace:*",
Expand Down
12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
"author": "Anton Evzhakov",
"bugs": "https://github.com/Anber/wyw-in-js/issues",
"devDependencies": {
"@babel/cli": "^7.23.0",
"@babel/eslint-parser": "^7.22.15",
"@babel/plugin-proposal-explicit-resource-management": "^7.23.0",
"@babel/preset-env": "^7.22.20",
"@babel/preset-react": "^7.22.15",
"@babel/preset-typescript": "^7.23.0",
"@babel/cli": "^7.23.4",
"@babel/eslint-parser": "^7.23.3",
"@babel/plugin-proposal-explicit-resource-management": "^7.23.3",
"@babel/preset-env": "^7.23.5",
"@babel/preset-react": "^7.23.3",
"@babel/preset-typescript": "^7.23.3",
"@changesets/cli": "^2.26.2",
"@changesets/get-release-plan": "^3.0.17",
"@changesets/write": "^0.2.3",
Expand Down
16 changes: 8 additions & 8 deletions packages/esbuild/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,14 @@ export default function wywInJS({
return result.path.replace(/\\/g, posix.sep);
};

build.onResolve({ filter: /\.linaria\.css$/ }, (args) => {
build.onResolve({ filter: /\.wyw\.css$/ }, (args) => {
return {
namespace: 'linaria',
namespace: 'wyw-in-js',
path: args.path,
};
});

build.onLoad({ filter: /.*/, namespace: 'linaria' }, (args) => {
build.onLoad({ filter: /.*/, namespace: 'wyw-in-js' }, (args) => {
return {
contents: cssLookup.get(args.path),
loader: 'css',
Expand Down Expand Up @@ -131,17 +131,17 @@ export default function wywInJS({
let { cssText } = result;

const slug = slugify(cssText);
const cssFilename = `${filename}_${slug}.linaria.css`;
const cssFilename = `${filename}_${slug}.wyw.css`;

let contents = `import ${JSON.stringify(cssFilename)}; ${result.code}`;

if (sourceMap && result.cssSourceMapText) {
const map = Buffer.from(result.cssSourceMapText).toString('base64');
cssText += `/*# sourceMappingURL=data:application/json;base64,${map}*/`;
const linariaMap = Buffer.from(
JSON.stringify(result.sourceMap)
).toString('base64');
contents += `/*# sourceMappingURL=data:application/json;base64,${linariaMap}*/`;
const wywMap = Buffer.from(JSON.stringify(result.sourceMap)).toString(
'base64'
);
contents += `/*# sourceMappingURL=data:application/json;base64,${wywMap}*/`;
}

cssLookup.set(cssFilename, cssText);
Expand Down
8 changes: 4 additions & 4 deletions packages/processor-utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
"name": "@wyw-in-js/processor-utils",
"version": "0.1.1",
"dependencies": {
"@babel/generator": "^7.23.0",
"@babel/generator": "^7.23.5",
"@wyw-in-js/shared": "workspace:*"
},
"devDependencies": {
"@babel/types": "^7.23.0",
"@types/babel__core": "^7.20.2",
"@types/babel__generator": "^7.6.5",
"@babel/types": "^7.23.5",
"@types/babel__core": "^7.20.5",
"@types/babel__generator": "^7.6.7",
"@types/node": "^16.18.55",
"@wyw-in-js/babel-config": "workspace:*",
"@wyw-in-js/eslint-config": "workspace:*",
Expand Down
5 changes: 3 additions & 2 deletions packages/shared/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
"version": "0.1.1",
"dependencies": {
"debug": "^4.3.4",
"find-up": "^5.0.0",
"minimatch": "^9.0.3"
},
"devDependencies": {
"@babel/types": "^7.23.0",
"@types/babel__core": "^7.20.2",
"@babel/types": "^7.23.5",
"@types/babel__core": "^7.20.5",
"@types/debug": "^4.1.9",
"@types/node": "^16.18.55",
"@wyw-in-js/babel-config": "workspace:*",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ export function findPackageJSON(
? filename
: require.resolve(
pkgName,
filename && !skipPathsOptions ? { paths: [dirname(filename)] } : {}
filename ? { paths: [dirname(filename)] } : {}
// filename && !skipPathsOptions ? { paths: [dirname(filename)] } : {}
);
if (!cache.has(pkgPath)) {
cache.set(pkgPath, findUp.sync('package.json', { cwd: pkgPath }));
Expand Down
2 changes: 2 additions & 0 deletions packages/shared/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ export { Debugger } from 'debug';

export { asyncResolveFallback, syncResolve } from './asyncResolveFallback';
export { hasEvalMeta } from './hasEvalMeta';
export { findPackageJSON } from './findPackageJSON';
export { isBoxedPrimitive } from './isBoxedPrimitive';
export { IVariableContext } from './IVariableContext';
export { enableDebug, logger } from './logger';
export { isFeatureEnabled } from './options/isFeatureEnabled';
export { slugify } from './slugify';
Expand Down
23 changes: 11 additions & 12 deletions packages/transform/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,31 @@
"name": "@wyw-in-js/transform",
"version": "0.1.1",
"dependencies": {
"@babel/core": "^7.23.0",
"@babel/generator": "^7.23.0",
"@babel/core": "^7.23.5",
"@babel/generator": "^7.23.5",
"@babel/helper-module-imports": "^7.22.15",
"@babel/plugin-transform-modules-commonjs": "^7.23.0",
"@babel/plugin-transform-modules-commonjs": "^7.23.3",
"@babel/template": "^7.22.15",
"@babel/traverse": "^7.23.0",
"@babel/types": "^7.23.0",
"@babel/traverse": "^7.23.5",
"@babel/types": "^7.23.5",
"@wyw-in-js/processor-utils": "workspace:*",
"@wyw-in-js/shared": "workspace:*",
"babel-merge": "^3.0.0",
"cosmiconfig": "^8.0.0",
"find-up": "^5.0.0",
"happy-dom": "^12.5.0",
"source-map": "^0.7.4",
"stylis": "^4.3.0",
"ts-invariant": "^0.10.3"
},
"devDependencies": {
"@babel/plugin-syntax-typescript": "^7.22.5",
"@babel/plugin-syntax-typescript": "^7.23.3",
"@babel/types": "^7.23.0",
"@swc/core": "1.3.20",
"@types/babel__core": "^7.20.2",
"@types/babel__generator": "^7.6.5",
"@types/babel__helper-module-imports": "^7.18.1",
"@types/babel__template": "^7.4.2",
"@types/babel__traverse": "^7.20.2",
"@types/babel__core": "^7.20.5",
"@types/babel__generator": "^7.6.7",
"@types/babel__helper-module-imports": "^7.18.3",
"@types/babel__template": "^7.4.4",
"@types/babel__traverse": "^7.20.4",
"@types/debug": "^4.1.9",
"@types/node": "^16.18.55",
"@types/stylis": "^4.2.4",
Expand Down
8 changes: 4 additions & 4 deletions packages/transform/src/__tests__/babel.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { TransformCacheCollection } from '../cache';
import shaker from '../shaker';
import { transform as linariaTransform } from '../transform';
import { Entrypoint } from '../transform/Entrypoint';
import { loadLinariaOptions } from '../transform/helpers/loadLinariaOptions';
import { loadWywOptions } from '../transform/helpers/loadWywOptions';
import type { PluginOptions, Stage } from '../types';
import type {
EntrypointEvent,
Expand Down Expand Up @@ -66,11 +66,11 @@ const getPresets = (extension: 'js' | 'ts' | 'jsx' | 'tsx') => {

const getLinariaConfig = (
evaluator: Evaluator,
linariaConfig: PartialOptions,
wywConfig: PartialOptions,
presets: PluginItem[],
stage?: Stage
): PluginOptions =>
loadLinariaOptions({
loadWywOptions({
babelOptions: {
presets,
plugins: [],
Expand All @@ -94,7 +94,7 @@ const getLinariaConfig = (
softErrors: false,
},
stage,
...linariaConfig,
...wywConfig,
});

async function transform(
Expand Down
1 change: 0 additions & 1 deletion packages/transform/src/__tests__/preeval.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ const run = (code: TemplateStringsArray) => {

return {
code: transformed.code,
// metadata: transformed.metadata.__linariaShaker,
};
};

Expand Down
4 changes: 2 additions & 2 deletions packages/transform/src/__tests__/prepareCode.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ import { join } from 'path';

import * as babel from '@babel/core';

import { loadWywOptions } from '../transform/helpers/loadWywOptions';
import shaker from '../shaker';
import { Entrypoint } from '../transform/Entrypoint';
import { parseFile } from '../transform/Entrypoint.helpers';
import { prepareCode } from '../transform/generators/transform';
import { loadLinariaOptions } from '../transform/helpers/loadLinariaOptions';
import { withDefaultServices } from '../transform/helpers/withDefaultServices';

const testCasesDir = join(__dirname, '__fixtures__', 'prepare-code-test-cases');
Expand All @@ -23,7 +23,7 @@ const rules = [
},
];

const pluginOptions = loadLinariaOptions({
const pluginOptions = loadWywOptions({
configFile: false,
rules,
babelOptions: {
Expand Down
8 changes: 4 additions & 4 deletions packages/transform/src/__tests__/transform.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import shaker from '../shaker';
import { transform } from '../transform';
import { transformUrl } from '../transform/generators/extract';

const outputFilename = './.linaria-cache/test.css';
const outputFilename = './.wyw-cache/test.css';

const rules = [
{
Expand All @@ -27,12 +27,12 @@ describe('transformUrl', () => {
const dataset: Record<string, TransformUrlArgs> = {
'../assets/test.jpg': [
'./assets/test.jpg',
'./.linaria-cache/test.css',
'./.wyw-cache/test.css',
'./test.js',
],
'../a/b/test.jpg': [
'../a/b/test.jpg',
'./.linaria-cache/test.css',
'./.wyw-cache/test.css',
'./a/test.js',
],
};
Expand Down Expand Up @@ -69,7 +69,7 @@ it.skip('rewrites a relative path in url() declarations', async () => {
{
options: {
filename: './test.js',
outputFilename: './.linaria-cache/test.css',
outputFilename: './.wyw-cache/test.css',
pluginOptions: {
rules,
},
Expand Down
11 changes: 9 additions & 2 deletions packages/transform/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export {
} from './utils/TransformMetadata';
export type { WYWTransformMetadata } from './utils/TransformMetadata';
export { Module, DefaultModuleImplementation } from './module';
export { default as shaker } from './shaker';
export { transform } from './transform';
export {
isUnprocessedEntrypointError,
Expand All @@ -27,10 +28,16 @@ export {
asyncResolveImports,
syncResolveImports,
} from './transform/generators/resolveImports';
export { loadLinariaOptions } from './transform/helpers/loadLinariaOptions';
export { loadWywOptions } from './transform/helpers/loadWywOptions';
export { withDefaultServices } from './transform/helpers/withDefaultServices';
export type { Services } from './transform/types';
export type { EventEmitter } from './utils/EventEmitter';
export { EventEmitter } from './utils/EventEmitter';
export type {
EntrypointEvent,
OnEvent,
OnActionStartArgs,
OnActionFinishArgs,
} from './utils/EventEmitter';
export { isNode } from './utils/isNode';
export { getFileIdx } from './utils/getFileIdx';
export { getTagProcessor } from './utils/getTagProcessor';
Expand Down
2 changes: 1 addition & 1 deletion packages/transform/src/options/loadBabelOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export function loadBabelOptions(
...overrides,
filename,
caller: {
name: 'linaria',
name: 'wyw-in-js',

// Indicates for @babel/preset-env to support all ESM syntax and avoid transforms before it's needed
supportsStaticESM: true,
Expand Down
4 changes: 2 additions & 2 deletions packages/transform/src/plugins/babel-transform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import type { BabelFile, PluginObj } from '@babel/core';

import { logger, syncResolve } from '@wyw-in-js/shared';

import { loadWywOptions } from '../transform/helpers/loadWywOptions';
import type { Core } from '../babel';
import { TransformCacheCollection } from '../cache';
import { transformSync } from '../transform';
import { loadLinariaOptions } from '../transform/helpers/loadLinariaOptions';
import type { ICollectAction, SyncScenarioForAction } from '../transform/types';
import type { IPluginState, PluginOptions } from '../types';

Expand Down Expand Up @@ -42,7 +42,7 @@ export default function babelTransform(

debug('start %s', file.opts.filename);

const pluginOptions = loadLinariaOptions(options);
const pluginOptions = loadWywOptions(options);

transformSync(
{
Expand Down
8 changes: 4 additions & 4 deletions packages/transform/src/plugins/collector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ export function collector(
return processors;
}

// We can remove __linariaPreval export and all related code
// We can remove __wywPreval export and all related code
const prevalExport = (
file.path.scope.getData('__linariaPreval') as NodePath | undefined
file.path.scope.getData('__wywPreval') as NodePath | undefined
)?.findParent((p) => p.isExpressionStatement());
if (prevalExport) {
removeWithRelated([prevalExport]);
Expand All @@ -76,11 +76,11 @@ export default function collectorPlugin(
const processors = collector(file, options, values);

if (processors.length === 0) {
// We didn't find any Linaria template literals.
// We didn't find any wyw-in-js template literals.
return;
}

this.file.metadata.linaria = {
this.file.metadata.wywInJS = {
processors,
replacements: [],
rules: {},
Expand Down
Loading

0 comments on commit 2fc6fd9

Please sign in to comment.