Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

replace .m.js with .mjs to be working in Node ESM #3

Merged
merged 1 commit into from
Jul 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dev-socket-client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"amdName": "sosseDevSocketClient",
"source": "lib/main.ts",
"main": "dist/main.js",
"module": "dist/main.m.js",
"module": "dist/main.mjs",
"umd:main": "dist/main.umd.js",
"esmodule": "dist/main.modern.js",
"types": "dist/main.d.ts"
Expand Down
2 changes: 1 addition & 1 deletion example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"amdName": "sosseExample",
"source": "lib/main.ts",
"main": "dist/main.js",
"module": "dist/main.m.js",
"module": "dist/main.mjs",
"umd:main": "dist/main.umd.js",
"esmodule": "dist/main.modern.js",
"types": "dist/main.d.ts"
Expand Down
2 changes: 1 addition & 1 deletion otion/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"amdName": "sosseOtion",
"source": "lib/main.ts",
"main": "dist/main.js",
"module": "dist/main.m.js",
"module": "dist/main.mjs",
"umd:main": "dist/main.umd.js",
"esmodule": "dist/main.modern.js",
"types": "dist/main.d.ts"
Expand Down
22 changes: 11 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,38 +5,38 @@
"description": "Spice your servers up with a lil Sosse",
"source": "lib/main.ts",
"main": "dist/main.js",
"module": "dist/main.m.js",
"module": "dist/main.mjs",
"umd:main": "dist/main.umd.js",
"esmodule": "dist/main.modern.js",
"exports": {
".": {
"browser": "./dist/main.m.js",
"browser": "./dist/main.mjs",
"umd": "./dist/main.umd.js",
"import": "./dist/main.m.js",
"import": "./dist/main.mjs",
"require": "./dist/main.js"
},
"./dev-socket-client": {
"browser": "./dev-socket-client/dist/main.m.js",
"browser": "./dev-socket-client/dist/main.mjs",
"umd": "./dev-socket-client/dist/main.umd.js",
"import": "./dev-socket-client/dist/main.m.js",
"import": "./dev-socket-client/dist/main.mjs",
"require": "./dev-socket-client/dist/main.js"
},
"./uni": {
"browser": "./uni/dist/main.m.js",
"browser": "./uni/dist/main.mjs",
"umd": "./uni/dist/main.umd.js",
"import": "./uni/dist/main.m.js",
"import": "./uni/dist/main.mjs",
"require": "./uni/dist/main.js"
},
"./react": {
"browser": "./react/dist/main.m.js",
"browser": "./react/dist/main.mjs",
"umd": "./react/dist/main.umd.js",
"import": "./react/dist/main.m.js",
"import": "./react/dist/main.mjs",
"require": "./react/dist/main.js"
},
"./preact": {
"browser": "./preact/dist/main.m.js",
"browser": "./preact/dist/main.mjs",
"umd": "./preact/dist/main.umd.js",
"import": "./preact/dist/main.m.js",
"import": "./preact/dist/main.mjs",
"require": "./preact/dist/main.js"
},
"./package.json": "./package.json",
Expand Down
2 changes: 1 addition & 1 deletion preact/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"amdName": "sossePreact",
"source": "lib/main.ts",
"main": "dist/main.js",
"module": "dist/main.m.js",
"module": "dist/main.mjs",
"umd:main": "dist/main.umd.js",
"esmodule": "dist/main.modern.js",
"types": "dist/main.d.ts"
Expand Down
2 changes: 1 addition & 1 deletion react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"amdName": "sosseReact",
"source": "lib/main.tsx",
"main": "dist/main.js",
"module": "dist/main.m.js",
"module": "dist/main.mjs",
"umd:main": "dist/main.umd.js",
"esmodule": "dist/main.modern.js",
"types": "dist/main.d.ts"
Expand Down
126 changes: 63 additions & 63 deletions scripts/module.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,88 +11,88 @@ const {
writeFile,
scriptsDir,
chmod,
} = require("./lib");
} = require('./lib')

const updatePkg = async function (moduleName, pkg) {
pkg.files.push(
`${moduleName}/package.json`,
`${moduleName}/lib`,
`${moduleName}/dist`
);
pkg.files = Array.from(new Set(pkg.files));
)
pkg.files = Array.from(new Set(pkg.files))

pkg.jest.collectCoverageFrom.push(`${moduleName}/lib/**/*.{ts,tsx,js,jsx}`);
pkg.jest.collectCoverageFrom.push(`${moduleName}/lib/**/*.{ts,tsx,js,jsx}`)
pkg.jest.collectCoverageFrom = Array.from(
new Set(pkg.jest.collectCoverageFrom)
);
)

const exportsBase = `./${moduleName}`;
const exportsBase = `./${moduleName}`
pkg.exports[exportsBase] = {
browser: `${exportsBase}/dist/main.m.js`,
browser: `${exportsBase}/dist/main.mjs`,
umd: `${exportsBase}/dist/main.umd.js`,
import: `${exportsBase}/dist/main.m.js`,
import: `${exportsBase}/dist/main.mjs`,
require: `${exportsBase}/dist/main.js`,
};
}

// These entries should stay at the very end of the exports object
for (const entry of ["./package.json", "./"]) {
for (const entry of ['./package.json', './']) {
if (!pkg.exports[entry]) {
continue;
continue
}

const value = pkg.exports[entry];
delete pkg.exports[entry];
pkg.exports[entry] = value;
const value = pkg.exports[entry]
delete pkg.exports[entry]
pkg.exports[entry] = value
}

await writeJson(pkgDir("package.json"), pkg, {
spaces: " ",
});
};
await writeJson(pkgDir('package.json'), pkg, {
spaces: ' ',
})
}

const updateTsconfig = async function (moduleName, pkg) {
const tsConfig = require("../tsconfig");
const pathAlias = `${pkg.name}/${moduleName}`;
const tsConfig = require('../tsconfig')
const pathAlias = `${pkg.name}/${moduleName}`

if (tsConfig.compilerOptions.paths[pathAlias]) {
return;
return
}

tsConfig.compilerOptions.paths[pathAlias] = [`../${moduleName}/lib/main.ts`];
const tsConfigPath = resolve(pkgDir("tsconfig.json"));
tsConfig.compilerOptions.paths[pathAlias] = [`../${moduleName}/lib/main.ts`]
const tsConfigPath = resolve(pkgDir('tsconfig.json'))
await writeJson(tsConfigPath, tsConfig, {
spaces: " ",
});
};
spaces: ' ',
})
}

const createModulePkg = async function (moduleDir, moduleName, pkg) {
const modulePkg = resolve(moduleDir, "package.json");
const modulePkg = resolve(moduleDir, 'package.json')
await writeJson(
modulePkg,
{
name: `${pkg.name}-${moduleName}`,
amdName: `${pkg.name}${upperFirst(moduleName)}`,
source: "lib/main.ts",
main: "dist/main.js",
module: "dist/main.m.js",
"umd:main": "dist/main.umd.js",
esmodule: "dist/main.modern.js",
types: "dist/main.d.ts",
source: 'lib/main.ts',
main: 'dist/main.js',
module: 'dist/main.mjs',
'umd:main': 'dist/main.umd.js',
esmodule: 'dist/main.modern.js',
types: 'dist/main.d.ts',
},
{
spaces: " ",
spaces: ' ',
}
);
};
)
}

const createModuleLib = async function (moduleDir) {
const moduleLibDir = resolve(moduleDir, "lib");
await mkDir(moduleLibDir);
const moduleLibDir = resolve(moduleDir, 'lib')
await mkDir(moduleLibDir)
await writeFile(
resolve(moduleLibDir, "main.ts"),
'export const hello = "world";' + "\n"
);
};
resolve(moduleLibDir, 'main.ts'),
'export const hello = "world";' + '\n'
)
}

const createBuildScript = async function (moduleName) {
const buildScript = `#!/usr/bin/env node
Expand All @@ -103,39 +103,39 @@ const { spawn, args, buildArgs, rmDir, pkgDir } = require("./lib");
await rmDir(pkgDir("${moduleName}", "dist"), { recursive: true });
spawn("npx", ["microbundle", "--cwd", "${moduleName}", "--raw", ...buildArgs(), ...args]);
})();
`;
`

const scriptPath = scriptsDir(`build-${moduleName}.js`);
await writeFile(scriptPath, buildScript);
await chmod(scriptPath, "755");
};
const scriptPath = scriptsDir(`build-${moduleName}.js`)
await writeFile(scriptPath, buildScript)
await chmod(scriptPath, '755')
}

(async () => {
;(async () => {
try {
const moduleName = (args[0] && args[0].trim()) || undefined;
const moduleName = (args[0] && args[0].trim()) || undefined

if (!moduleName) {
console.error("Module name missing in arguments.");
return;
console.error('Module name missing in arguments.')
return
}

const moduleDir = pkgDir(moduleName);
const moduleDir = pkgDir(moduleName)

if (await exists(moduleDir)) {
console.error(`"${moduleDir}" already exists.`);
return;
console.error(`"${moduleDir}" already exists.`)
return
}

await mkDir(moduleDir);
await mkDir(moduleDir)

const pkg = require("./../package");
const pkg = require('./../package')

await updatePkg(moduleName, pkg);
await updateTsconfig(moduleName, pkg);
await createModulePkg(moduleDir, moduleName, pkg);
await createModuleLib(moduleDir);
await createBuildScript(moduleName);
await updatePkg(moduleName, pkg)
await updateTsconfig(moduleName, pkg)
await createModulePkg(moduleDir, moduleName, pkg)
await createModuleLib(moduleDir)
await createBuildScript(moduleName)
} catch (err) {
console.error(err);
console.error(err)
}
})();
})()
2 changes: 1 addition & 1 deletion site/main.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion site/main.m.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion site/main.m.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion site/main.modern.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion site/main.umd.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion uni/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"amdName": "sosseUni",
"source": "lib/main.ts",
"main": "dist/main.js",
"module": "dist/main.m.js",
"module": "dist/main.mjs",
"umd:main": "dist/main.umd.js",
"esmodule": "dist/main.modern.js",
"types": "dist/main.d.ts"
Expand Down