Skip to content

Commit

Permalink
change ~ remove experimental 'meta.mainFilename' prior to publish
Browse files Browse the repository at this point in the history
  • Loading branch information
rivy committed Jan 15, 2021
1 parent 6d58d39 commit 461f9ac
Show file tree
Hide file tree
Showing 7 changed files with 3 additions and 20 deletions.
8 changes: 0 additions & 8 deletions src/esm-wrapper/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,6 @@
// # spell-checker:ignore Deno

import _ from '../index.js';
// note: not usable by `deno`;
// ...`deno` is unable to load (the CJS module) '../index.js' via import => `'../index.js' does not provide an export named 'default'`
import { adapter } from '../platform-adapters/node.js';

// re-define `meta.mainFilename` adapter for ESM scripts
// HACK: `process._eval` is undocumented; used here as evidence of `node -e ...` differentiating between immediate eval vs file-bound scripts
// eslint-disable-next-line functional/immutable-data
adapter.meta.mainFilename = typeof process._eval === 'undefined' ? process.argv[1] : '';

const default_ = _;
export default default_;
2 changes: 1 addition & 1 deletion src/lib/OSPaths.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ type moduleInternals_ = typeof module_ & {
};

test('api', (t) => {
const api = ['home', 'temp', 'main'];
const api = ['home', 'temp'];

t.is(typeof module_, 'function');
t.deepEqual(Object.keys(module_).sort(), api.sort());
Expand Down
6 changes: 1 addition & 5 deletions src/lib/OSPaths.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,14 @@ export type OSPaths = {
(): OSPaths;
readonly home: () => string | undefined;
readonly temp: () => string;
readonly main: () => string;
};

function isEmpty(s: string | null | undefined): boolean {
return !s; // reminder: JS "falsey" == [undefined, null, NaN, 0, '', false]
}

export function OSPathsAdaptionBuilder_(adapter_: Platform.Adapter): OSPaths {
const { env, meta, os, path, process } = adapter_;
const { env, os, path, process } = adapter_;

const isWinOS = /^win/i.test(process.platform);

Expand Down Expand Up @@ -89,9 +88,6 @@ export function OSPathsAdaptionBuilder_(adapter_: Platform.Adapter): OSPaths {
const platformOS = isWinOS ? windows() : posix();
OSPaths.home = platformOS.home;
OSPaths.temp = platformOS.temp;
OSPaths.main = () => {
return meta.mainFilename;
};

return OSPaths;
}
Expand Down
1 change: 0 additions & 1 deletion src/platform-adapters/_base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
export namespace Platform {
export type Adapter = {
readonly env: { readonly get: (_: string) => string | undefined };
readonly meta: { readonly mainFilename: string };
readonly os: { readonly homedir?: () => string; readonly tmpdir?: () => string };
readonly path: {
readonly join: (..._: readonly string[]) => string;
Expand Down
1 change: 0 additions & 1 deletion src/platform-adapters/deno.deno.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ export const adapter: Platform.Adapter = {
env: { get: deno.env.get },
// Deno (as of v1.6) has no built-in implementation for homedir() or tmpdir()
os: {}, // * module is tolerant of missing homedir()/tmpdir() functions
meta: { mainFilename: deno.mainModule },
path,
process: { platform: deno.build.os },
};
Expand Down
3 changes: 0 additions & 3 deletions src/platform-adapters/node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@ export const adapter: Platform.Adapter = {
return process.env[s];
},
},
meta: {
mainFilename: process.mainModule?.filename || '',
},
os,
path,
process,
Expand Down
2 changes: 1 addition & 1 deletion test/integration.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const settledSupportForESMs =
// Integration tests

test('api', (t) => {
const api = ['home', 'temp', 'main'];
const api = ['home', 'temp'];

t.is(typeof module_, 'function');
t.deepEqual(Object.keys(module_).sort(), api.sort());
Expand Down

0 comments on commit 461f9ac

Please sign in to comment.