one
Version:
One is a new React Framework that makes Vite serve both native and web.
91 lines (89 loc) • 5.01 kB
JavaScript
;
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
get: () => from[key],
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
});
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
value: mod,
enumerable: true
}) : target, mod));
var import_fs = __toESM(require("fs"), 1);
var import_path = __toESM(require("path"), 1);
var import_vitest = require("vitest");
var import_getViteMetroPluginOptions = require("./getViteMetroPluginOptions.native.js");
(0, import_vitest.describe)("getViteMetroPluginOptions babel-config coexistence", function () {
var tmpDir;
(0, import_vitest.beforeAll)(function () {
var workspaceRoot = import_path.default.resolve(__dirname, "../../../../");
tmpDir = import_fs.default.mkdtempSync(import_path.default.join(workspaceRoot, ".tmp-one-vite-metro-test-"));
import_fs.default.writeFileSync(import_path.default.join(tmpDir, "tsconfig.json"), JSON.stringify({
compilerOptions: {
paths: {}
}
}));
import_fs.default.writeFileSync(import_path.default.join(tmpDir, "package.json"), JSON.stringify({
name: "tmp"
}));
});
(0, import_vitest.afterAll)(function () {
import_fs.default.rmSync(tmpDir, {
recursive: true,
force: true
});
});
(0, import_vitest.it)("injects plugins when there is no user babel.config", function () {
var _opts_babelConfig, _opts_babelConfig_plugins, _opts_babelConfig1;
var opts = (0, import_getViteMetroPluginOptions.getViteMetroPluginOptions)({
projectRoot: tmpDir,
relativeRouterRoot: "app"
});
(0, import_vitest.expect)(opts === null || opts === void 0 ? void 0 : (_opts_babelConfig = opts.babelConfig) === null || _opts_babelConfig === void 0 ? void 0 : _opts_babelConfig.plugins).toBeDefined();
(0, import_vitest.expect)(opts === null || opts === void 0 ? void 0 : opts.oneViteMetroBabelConfig).toBe(true);
(0, import_vitest.expect)(opts === null || opts === void 0 ? void 0 : (_opts_babelConfig1 = opts.babelConfig) === null || _opts_babelConfig1 === void 0 ? void 0 : (_opts_babelConfig_plugins = _opts_babelConfig1.plugins) === null || _opts_babelConfig_plugins === void 0 ? void 0 : _opts_babelConfig_plugins.length).toBe(5);
});
(0, import_vitest.it)("still injects One plugins when the user has a babel.config.cjs", function () {
var cfgPath = import_path.default.join(tmpDir, "babel.config.cjs");
import_fs.default.writeFileSync(cfgPath, "module.exports = require('one/babel-preset')\n");
try {
var _opts_babelConfig_plugins, _opts_babelConfig;
var opts = (0, import_getViteMetroPluginOptions.getViteMetroPluginOptions)({
projectRoot: tmpDir,
relativeRouterRoot: "app"
});
(0, import_vitest.expect)(opts === null || opts === void 0 ? void 0 : (_opts_babelConfig = opts.babelConfig) === null || _opts_babelConfig === void 0 ? void 0 : (_opts_babelConfig_plugins = _opts_babelConfig.plugins) === null || _opts_babelConfig_plugins === void 0 ? void 0 : _opts_babelConfig_plugins.length).toBe(5);
} finally {
import_fs.default.unlinkSync(cfgPath);
}
});
(0, import_vitest.it)("still injects One plugins when the user has a babel.config.js", function () {
var cfgPath = import_path.default.join(tmpDir, "babel.config.js");
import_fs.default.writeFileSync(cfgPath, "module.exports = require('one/babel-preset')\n");
try {
var _opts_babelConfig_plugins, _opts_babelConfig;
var opts = (0, import_getViteMetroPluginOptions.getViteMetroPluginOptions)({
projectRoot: tmpDir,
relativeRouterRoot: "app"
});
(0, import_vitest.expect)(opts === null || opts === void 0 ? void 0 : (_opts_babelConfig = opts.babelConfig) === null || _opts_babelConfig === void 0 ? void 0 : (_opts_babelConfig_plugins = _opts_babelConfig.plugins) === null || _opts_babelConfig_plugins === void 0 ? void 0 : _opts_babelConfig_plugins.length).toBe(5);
} finally {
import_fs.default.unlinkSync(cfgPath);
}
});
});
//# sourceMappingURL=getViteMetroPluginOptions.integration.test.native.js.map