@aljazmc/testero 0.3.0 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/main.js +27 -9
- package/package.json +1 -1
package/bin/main.js
CHANGED
|
@@ -1667,6 +1667,8 @@ var Transformer = class _Transformer {
|
|
|
1667
1667
|
".mts": "ts",
|
|
1668
1668
|
".tsx": "tsx"
|
|
1669
1669
|
};
|
|
1670
|
+
/** The import.meta properties that describe the source file. */
|
|
1671
|
+
static #meta = ["url", "filename", "dirname"];
|
|
1670
1672
|
/** Marks the resolutions the plugin asks esbuild for itself. */
|
|
1671
1673
|
static #own = /* @__PURE__ */ Symbol("testero");
|
|
1672
1674
|
/** Where compiled test files go, stack frames there are testero's own. */
|
|
@@ -1691,6 +1693,12 @@ var Transformer = class _Transformer {
|
|
|
1691
1693
|
sourcemap: "inline",
|
|
1692
1694
|
sourcesContent: false,
|
|
1693
1695
|
inject: [this.#globals],
|
|
1696
|
+
define: Object.fromEntries(
|
|
1697
|
+
_Transformer.#meta.map((name) => [
|
|
1698
|
+
`import.meta.${name}`,
|
|
1699
|
+
`__testero.${name}`
|
|
1700
|
+
])
|
|
1701
|
+
),
|
|
1694
1702
|
// CommonJS code in the bundle may require installed packages
|
|
1695
1703
|
banner: {
|
|
1696
1704
|
js: 'import { createRequire as __testeroRequire } from "node:module";\nconst require = __testeroRequire(import.meta.url);'
|
|
@@ -1709,6 +1717,21 @@ var Transformer = class _Transformer {
|
|
|
1709
1717
|
return {
|
|
1710
1718
|
name: "testero",
|
|
1711
1719
|
setup: (build2) => {
|
|
1720
|
+
build2.onResolve({ filter: /^testero-meta:/ }, (args) => ({
|
|
1721
|
+
path: args.path.slice("testero-meta:".length),
|
|
1722
|
+
namespace: "testero-meta"
|
|
1723
|
+
}));
|
|
1724
|
+
build2.onLoad(
|
|
1725
|
+
{ filter: /.*/, namespace: "testero-meta" },
|
|
1726
|
+
(args) => ({
|
|
1727
|
+
contents: `export default ${JSON.stringify({
|
|
1728
|
+
url: pathToFileURL2(args.path).href,
|
|
1729
|
+
filename: args.path,
|
|
1730
|
+
dirname: dirname(args.path)
|
|
1731
|
+
})};`,
|
|
1732
|
+
loader: "js"
|
|
1733
|
+
})
|
|
1734
|
+
);
|
|
1712
1735
|
build2.onResolve({ filter: /^[^./]/ }, async (args) => {
|
|
1713
1736
|
if (args.pluginData === _Transformer.#own) return void 0;
|
|
1714
1737
|
if (_Transformer.modules.includes(args.path))
|
|
@@ -1731,15 +1754,10 @@ var Transformer = class _Transformer {
|
|
|
1731
1754
|
});
|
|
1732
1755
|
build2.onLoad({ filter: /\.[cm]?[jt]sx?$/ }, (args) => {
|
|
1733
1756
|
if (_Transformer.#installed(args.path)) return void 0;
|
|
1734
|
-
const
|
|
1735
|
-
|
|
1736
|
-
|
|
1737
|
-
|
|
1738
|
-
};
|
|
1739
|
-
const contents = readFileSync2(args.path, "utf8").replace(
|
|
1740
|
-
/\bimport\.meta\.(url|filename|dirname)\b/g,
|
|
1741
|
-
(_, name) => JSON.stringify(values[name])
|
|
1742
|
-
);
|
|
1757
|
+
const source = readFileSync2(args.path, "utf8");
|
|
1758
|
+
const contents = /\bimport\.meta\b/.test(source) ? `${source}
|
|
1759
|
+
import __testero from ${JSON.stringify(`testero-meta:${args.path}`)};
|
|
1760
|
+
` : source;
|
|
1743
1761
|
return {
|
|
1744
1762
|
contents,
|
|
1745
1763
|
loader: _Transformer.#loaders[extname(args.path)] ?? "js",
|