Skip to content
This repository has been archived by the owner on Oct 9, 2024. It is now read-only.

Commit

Permalink
Merge pull request #12 from mohebifar/add-babel-plugin
Browse files Browse the repository at this point in the history
Add babel plugin
  • Loading branch information
mohebifar committed Feb 28, 2024
2 parents d1b5a51 + 272f9fd commit 90555ec
Show file tree
Hide file tree
Showing 9 changed files with 294 additions and 4 deletions.
6 changes: 6 additions & 0 deletions .changeset/nervous-ducks-grow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@react-unforget/babel-plugin": patch
"@react-unforget/compiler": patch
---

Add babel plugin
1 change: 1 addition & 0 deletions packages/babel-plugin/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# `@react-unforget/babel-plugin`
201 changes: 201 additions & 0 deletions packages/babel-plugin/jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,201 @@
/**
* For a detailed explanation regarding each configuration property, visit:
* https://jestjs.io/docs/configuration
*/

import type { Config } from "jest";

const config: Config = {
// All imported modules in your tests should be mocked automatically
// automock: false,

// Stop running tests after `n` failures
// bail: 0,

// The directory where Jest should store its cached dependency information
// cacheDirectory: "/private/var/folders/ff/q87d0vgd6_nfzq_1vs6s7qxr0000gn/T/jest_dx",

// Automatically clear mock calls, instances, contexts and results before every test
clearMocks: true,

// Indicates whether the coverage information should be collected while executing the test
// collectCoverage: false,

// An array of glob patterns indicating a set of files for which coverage information should be collected
// collectCoverageFrom: undefined,

// The directory where Jest should output its coverage files
// coverageDirectory: undefined,

// An array of regexp pattern strings used to skip coverage collection
// coveragePathIgnorePatterns: [
// "/node_modules/"
// ],

// Indicates which provider should be used to instrument code for coverage
// coverageProvider: "babel",

// A list of reporter names that Jest uses when writing coverage reports
// coverageReporters: [
// "json",
// "text",
// "lcov",
// "clover"
// ],

// An object that configures minimum threshold enforcement for coverage results
// coverageThreshold: undefined,

// A path to a custom dependency extractor
// dependencyExtractor: undefined,

// Make calling deprecated APIs throw helpful error messages
// errorOnDeprecated: false,

// The default configuration for fake timers
// fakeTimers: {
// "enableGlobally": false
// },

// Force coverage collection from ignored files using an array of glob patterns
// forceCoverageMatch: [],

// A path to a module which exports an async function that is triggered once before all test suites
// globalSetup: undefined,

// A path to a module which exports an async function that is triggered once after all test suites
// globalTeardown: undefined,

// A set of global variables that need to be available in all test environments
// globals: {},

// The maximum amount of workers used to run your tests. Can be specified as % or a number. E.g. maxWorkers: 10% will use 10% of your CPU amount + 1 as the maximum worker number. maxWorkers: 2 will use a maximum of 2 workers.
// maxWorkers: "50%",

// An array of directory names to be searched recursively up from the requiring module's location
// moduleDirectories: [
// "node_modules"
// ],

// An array of file extensions your modules use
// moduleFileExtensions: [
// "js",
// "mjs",
// "cjs",
// "jsx",
// "ts",
// "tsx",
// "json",
// "node"
// ],

// A map from regular expressions to module names or to arrays of module names that allow to stub out resources with a single module
moduleNameMapper: {
"^~/(.*)$": "<rootDir>/src/$1",
},

// An array of regexp pattern strings, matched against all module paths before considered 'visible' to the module loader
// modulePathIgnorePatterns: [],

// Activates notifications for test results
// notify: false,

// An enum that specifies notification mode. Requires { notify: true }
// notifyMode: "failure-change",

// A preset that is used as a base for Jest's configuration
preset: "ts-jest",

// Run tests from one or more projects
// projects: undefined,

// Use this configuration option to add custom reporters to Jest
// reporters: undefined,

// Automatically reset mock state before every test
// resetMocks: false,

// Reset the module registry before running each individual test
// resetModules: false,

// A path to a custom resolver
// resolver: undefined,

// Automatically restore mock state and implementation before every test
// restoreMocks: false,

// The root directory that Jest should scan for tests and modules within
// rootDir: undefined,

// A list of paths to directories that Jest should use to search for files in
// roots: [
// "<rootDir>"
// ],

// Allows you to use a custom runner instead of Jest's default test runner
// runner: "jest-runner",

// The paths to modules that run some code to configure or set up the testing environment before each test
// setupFiles: [],

// A list of paths to modules that run some code to configure or set up the testing framework before each test
// setupFilesAfterEnv: [],

// The number of seconds after which a test is considered as slow and reported as such in the results.
// slowTestThreshold: 5,

// A list of paths to snapshot serializer modules Jest should use for snapshot testing
// snapshotSerializers: [],

// The test environment that will be used for testing
testEnvironment: "jsdom",

// Options that will be passed to the testEnvironment
// testEnvironmentOptions: {},

// Adds a location field to test results
// testLocationInResults: false,

// The glob patterns Jest uses to detect test files
// testMatch: [
// "**/__tests__/**/*.[jt]s?(x)",
// "**/?(*.)+(spec|test).[tj]s?(x)"
// ],

// An array of regexp pattern strings that are matched against all test paths, matched tests are skipped
// testPathIgnorePatterns: [
// "/node_modules/"
// ],

// The regexp pattern or array of patterns that Jest uses to detect test files
// testRegex: [],

// This option allows the use of a custom results processor
// testResultsProcessor: undefined,

// This option allows use of a custom test runner
// testRunner: "jest-circus/runner",

// A map from regular expressions to paths to transformers
// transform: undefined,

// An array of regexp pattern strings that are matched against all source file paths, matched files will skip transformation
// transformIgnorePatterns: [
// "/node_modules/",
// "\\.pnp\\.[^\\/]+$"
// ],

// An array of regexp pattern strings that are matched against all modules before the module loader will automatically return a mock for them
// unmockedModulePathPatterns: undefined,

// Indicates whether each individual test should be reported during the run
// verbose: undefined,

// An array of regexp patterns that are matched against all source file paths before re-running tests in watch mode
// watchPathIgnorePatterns: [],

// Whether to use watchman for file crawling
// watchman: true,
};

export default config;
38 changes: 38 additions & 0 deletions packages/babel-plugin/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"name": "@react-unforget/babel-plugin",
"version": "0.1.0-dev.3",
"license": "MIT",
"type": "module",
"files": [
"dist",
"README.md"
],
"main": "dist/index.js",
"module": "dist/index.mjs",
"types": "dist/index.d.ts",
"exports": {
"require": "./dist/index.js",
"import": "./dist/index.mjs",
"types": "./dist/index.d.ts"
},
"scripts": {
"dev": "yarn build --watch",
"build": "tsup src/index.ts --format cjs,esm --dts",
"test": "echo 'No checks yet'",
"lint": "echo 'No checks yet'"
},
"dependencies": {
"@react-unforget/compiler": "latest"
},
"devDependencies": {
"@react-unforget/eslint-config": "*",
"@react-unforget/jest-config": "*",
"@react-unforget/typescript-config": "*",
"@types/react": "^18.2.58",
"react": "^18.2.0",
"tsup": "^8.0.2"
},
"publishConfig": {
"access": "public"
}
}
15 changes: 15 additions & 0 deletions packages/babel-plugin/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import type { NodePath } from "@babel/traverse";
import type * as t from "@babel/types";
import { visitProgram } from "@react-unforget/compiler";

export interface Options {}

export default function asyncBabelPlugin() {
return {
visitor: {
Program(path: NodePath<t.Program>) {
visitProgram(path);
},
},
};
}
11 changes: 11 additions & 0 deletions packages/babel-plugin/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"extends": "@react-unforget/typescript-config/react-library.json",
"compilerOptions": {
"allowSyntheticDefaultImports": false,
"baseUrl": "./src",
"paths": {
"~/*": ["./*"]
}
},
"exclude": ["node_modules"]
}
9 changes: 9 additions & 0 deletions packages/babel-plugin/tsup.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { defineConfig } from "tsup";

export default defineConfig({
entry: ["src/index.ts"],
splitting: false,
sourcemap: true,
clean: true,
bundle: true,
});
8 changes: 4 additions & 4 deletions packages/compiler/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
"dist",
"README.md"
],
"main": "dist/main.js",
"module": "dist/main.mjs",
"main": "dist/main.cjs",
"module": "dist/main.js",
"types": "dist/main.d.ts",
"exports": {
".": {
"import": "./dist/main.mjs",
"require": "./dist/main.js",
"import": "./dist/main.js",
"require": "./dist/main.cjs",
"types": "./dist/main.d.ts"
}
},
Expand Down
9 changes: 9 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1082,6 +1082,15 @@
resolved "https://registry.yarnpkg.com/@pkgr/core/-/core-0.1.1.tgz#1ec17e2edbec25c8306d424ecfbf13c7de1aaa31"
integrity sha512-cq8o4cWH0ibXh9VGi5P20Tu9XF/0fFXl9EUinr9QfTM7a7p0oTA4iJRCQWppXR1Pg8dSM0UCItCkPwsk9qWWYA==

"@react-unforget/compiler@latest":
version "0.1.0-dev.4"
resolved "https://registry.yarnpkg.com/@react-unforget/compiler/-/compiler-0.1.0-dev.4.tgz#9152ae9e09b9aeda3c5d1938fc5a6daeb81bbae2"
integrity sha512-zRamc1ESnLRprTBsBN51zV9jOqgWisgDNCxCGze6XaYpwdj3QbTC6zZy64eAIh/fyryEhuG2jspqKWOzQ4N5ow==
dependencies:
"@babel/core" "^7.23.9"
"@babel/parser" "^7.23.9"
"@babel/traverse" "^7.23.9"

"@rollup/[email protected]":
version "4.12.0"
resolved "https://registry.yarnpkg.com/@rollup/rollup-android-arm-eabi/-/rollup-android-arm-eabi-4.12.0.tgz#38c3abd1955a3c21d492af6b1a1dca4bb1d894d6"
Expand Down

0 comments on commit 90555ec

Please sign in to comment.