Skip to content

Commit

Permalink
test: add example cross-platform
Browse files Browse the repository at this point in the history
  • Loading branch information
shigma committed Feb 11, 2024
1 parent 6f4c67a commit 06952a1
Show file tree
Hide file tree
Showing 12 changed files with 161 additions and 0 deletions.
11 changes: 11 additions & 0 deletions examples/cross-platform/lib/adapter/browser.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
var __defProp = Object.defineProperty;
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });

// src/adapter/browser.ts
function platform() {
return "browser";
}
__name(platform, "platform");
export {
platform
};
1 change: 1 addition & 0 deletions examples/cross-platform/lib/adapter/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
declare function platform(): string
33 changes: 33 additions & 0 deletions examples/cross-platform/lib/adapter/node.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
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 __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// src/adapter/node.ts
var node_exports = {};
__export(node_exports, {
platform: () => platform
});
module.exports = __toCommonJS(node_exports);
function platform() {
return "node";
}
__name(platform, "platform");
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
platform
});
11 changes: 11 additions & 0 deletions examples/cross-platform/lib/adapter/node.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
var __defProp = Object.defineProperty;
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });

// src/adapter/node.ts
function platform() {
return "node";
}
__name(platform, "platform");
export {
platform
};
36 changes: 36 additions & 0 deletions examples/cross-platform/lib/index.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
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 __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// src/index.ts
var src_exports = {};
__export(src_exports, {
foo: () => foo,
platform: () => import_adapter.platform
});
module.exports = __toCommonJS(src_exports);
var import_adapter = require("@dunble-examples/cross-platform/adapter");
function foo() {
return console.log(platform());
}
__name(foo, "foo");
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
foo,
platform
});
13 changes: 13 additions & 0 deletions examples/cross-platform/lib/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
var __defProp = Object.defineProperty;
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });

// src/index.ts
import { platform as platform2 } from "@dunble-examples/cross-platform/adapter";
function foo() {
return console.log(platform());
}
__name(foo, "foo");
export {
foo,
platform2 as platform
};
31 changes: 31 additions & 0 deletions examples/cross-platform/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"name": "@dunble-examples/cross-platform",
"version": "0.0.0",
"private": true,
"type": "module",
"bin": "lib/bin.js",
"exports": {
".": {
"require": "./lib/index.cjs",
"import": "./lib/index.js",
"types": "./lib/index.d.ts"
},
"./adapter": {
"node": {
"require": "./lib/adapter/node.cjs",
"import": "./lib/adapter/node.js"
},
"browser": {
"import": "./lib/adapter/browser.js"
},
"types": "./lib/adapter/index.d.ts"
},
"./package.json": "./package.json"
},
"scripts": {
"build": "dunble"
},
"dependencies": {
"dunble": "^0.1.0"
}
}
3 changes: 3 additions & 0 deletions examples/cross-platform/src/adapter/browser.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export function platform() {
return 'browser'
}
1 change: 1 addition & 0 deletions examples/cross-platform/src/adapter/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
declare function platform(): string
3 changes: 3 additions & 0 deletions examples/cross-platform/src/adapter/node.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export function platform() {
return 'node'
}
5 changes: 5 additions & 0 deletions examples/cross-platform/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export { platform } from '@dunble-examples/cross-platform/adapter'

export function foo() {
return console.log(platform())
}
13 changes: 13 additions & 0 deletions examples/cross-platform/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"compilerOptions": {
"rootDir": "src",
"outDir": "lib",
"target": "esnext",
"module": "nodenext",
"declaration": true,
"emitDeclarationOnly": true,
},
"include": [
"src",
],
}

0 comments on commit 06952a1

Please sign in to comment.