@knighted/duel 1.0.0-rc.4 → 1.0.0-rc.6

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/README.md CHANGED
@@ -116,5 +116,5 @@ These are definitely edge cases, and would only really come up if your project m
116
116
 
117
117
  ## Notes
118
118
 
119
- As far as I can tell, `duel` is one (if not the only) way to get a correct dual package build using only `tsc` while using only **one package.json** file and **one tsconfig.json** file, _and also_ preserving module system by file extension. The Microsoft backed TypeScript team [keep](https://github.com/microsoft/TypeScript/issues/54593) [talking](https://github.com/microsoft/TypeScript/pull/54546) about dual build support, but their philosophy is mainly one of self-preservation, rather than collaboration. For instance, they continue to [refuse to rewrite specifiers](https://github.com/microsoft/TypeScript/issues/16577). The downside of their decisions, and the fact that `npm` does not support using alternative names for the package.json file, is that `duel` must copy your project
119
+ As far as I can tell, `duel` is one (if not the only) way to get a correct dual package build using `tsc` while using only **one package.json** file and **one tsconfig.json** file, _and also preserving module system by file extension_. The Microsoft backed TypeScript team [keep](https://github.com/microsoft/TypeScript/issues/54593) [talking](https://github.com/microsoft/TypeScript/pull/54546) about dual build support, but their philosophy is mainly one of self-preservation, rather than collaboration. For instance, they continue to [refuse to rewrite specifiers](https://github.com/microsoft/TypeScript/issues/16577). The downside of their decisions, and the fact that `npm` does not support using alternative names for the package.json file, is that `duel` must copy your project
120
120
  directory before attempting to run the builds in parallel.
package/dist/duel.cjs CHANGED
@@ -54,19 +54,18 @@ const duel = async args => {
54
54
  const isCjsBuild = originalType !== 'commonjs';
55
55
  const targetExt = isCjsBuild ? '.cjs' : '.mjs';
56
56
  const hex = (0, _nodeCrypto.randomBytes)(4).toString('hex');
57
- const getOverrideTsConfig = dualOutDir => {
57
+ const getOverrideTsConfig = () => {
58
58
  return {
59
59
  ...tsconfig,
60
60
  compilerOptions: {
61
61
  ...tsconfig.compilerOptions,
62
- outDir: dualOutDir,
63
62
  module: 'NodeNext',
64
63
  moduleResolution: 'NodeNext'
65
64
  }
66
65
  };
67
66
  };
68
67
  const runPrimaryBuild = () => {
69
- return runBuild(configPath, dirs ? isCjsBuild ? (0, _nodePath.join)(projectDir, outDir, 'esm') : (0, _nodePath.join)(projectDir, outDir, 'cjs') : undefined);
68
+ return runBuild(configPath, dirs ? isCjsBuild ? (0, _nodePath.join)(absoluteOutDir, 'esm') : (0, _nodePath.join)(absoluteOutDir, 'cjs') : absoluteOutDir);
70
69
  };
71
70
  const updateSpecifiersAndFileExtensions = async filenames => {
72
71
  for (const filename of filenames) {
@@ -92,10 +91,6 @@ const duel = async args => {
92
91
  const logSuccess = start => {
93
92
  (0, _util.log)(`Successfully created a dual ${isCjsBuild ? 'CJS' : 'ESM'} build in ${Math.round(_nodePerf_hooks.performance.now() - start)}ms.`);
94
93
  };
95
- await (0, _promises.rm)(absoluteOutDir, {
96
- force: true,
97
- recursive: true
98
- });
99
94
  if (parallel) {
100
95
  const paraName = `_${hex}_`;
101
96
  const paraParent = (0, _nodePath.join)(projectDir, '..');
@@ -128,8 +123,8 @@ const duel = async args => {
128
123
  filter: src => !/logs|pids|lib-cov|coverage|bower_components|build|dist|jspm_packages|web_modules|out|\.next|\.tsbuildinfo|\.npm|\.node_repl_history|\.tgz|\.yarn|\.pnp|\.nyc_output|\.grunt/i.test(src)
129
124
  });
130
125
  const dualConfigPath = (0, _nodePath.join)(paraTempDir, 'tsconfig.json');
131
- const dualOutDir = isCjsBuild ? (0, _nodePath.join)(outDir, 'cjs') : (0, _nodePath.join)(outDir, 'esm');
132
- const tsconfigDual = getOverrideTsConfig(dualOutDir);
126
+ const absoluteDualOutDir = (0, _nodePath.join)(paraTempDir, isCjsBuild ? (0, _nodePath.join)(outDir, 'cjs') : (0, _nodePath.join)(outDir, 'esm'));
127
+ const tsconfigDual = getOverrideTsConfig();
133
128
  await (0, _promises.writeFile)(dualConfigPath, JSON.stringify(tsconfigDual));
134
129
  await (0, _promises.writeFile)((0, _nodePath.join)(paraTempDir, 'package.json'), JSON.stringify({
135
130
  type: isCjsBuild ? 'commonjs' : 'module'
@@ -139,7 +134,7 @@ const duel = async args => {
139
134
  let success = false;
140
135
  const startTime = _nodePerf_hooks.performance.now();
141
136
  try {
142
- await Promise.all([runPrimaryBuild(), runBuild(dualConfigPath)]);
137
+ await Promise.all([runPrimaryBuild(), runBuild(dualConfigPath, absoluteDualOutDir)]);
143
138
  success = true;
144
139
  } catch ({
145
140
  message
@@ -147,13 +142,14 @@ const duel = async args => {
147
142
  (0, _util.logError)(message);
148
143
  }
149
144
  if (success) {
150
- const absoluteDualOutDir = (0, _nodePath.join)(paraTempDir, dualOutDir);
151
145
  const filenames = await (0, _glob.glob)(`${absoluteDualOutDir}/**/*{.js,.d.ts}`, {
152
146
  ignore: 'node_modules/**'
153
147
  });
154
148
  await updateSpecifiersAndFileExtensions(filenames);
155
149
  // Copy over and cleanup
156
- await (0, _promises.rename)(absoluteDualOutDir, (0, _nodePath.join)(absoluteOutDir, isCjsBuild ? 'cjs' : 'esm'));
150
+ await (0, _promises.cp)(absoluteDualOutDir, (0, _nodePath.join)(absoluteOutDir, isCjsBuild ? 'cjs' : 'esm'), {
151
+ recursive: true
152
+ });
157
153
  await (0, _promises.rm)(paraTempDir, {
158
154
  force: true,
159
155
  recursive: true
@@ -174,8 +170,8 @@ const duel = async args => {
174
170
  }
175
171
  if (success) {
176
172
  const dualConfigPath = (0, _nodePath.join)(projectDir, `tsconfig.${hex}.json`);
177
- const dualOutDir = isCjsBuild ? (0, _nodePath.join)(outDir, 'cjs') : (0, _nodePath.join)(outDir, 'esm');
178
- const tsconfigDual = getOverrideTsConfig(dualOutDir);
173
+ const absoluteDualOutDir = (0, _nodePath.join)(projectDir, isCjsBuild ? (0, _nodePath.join)(outDir, 'cjs') : (0, _nodePath.join)(outDir, 'esm'));
174
+ const tsconfigDual = getOverrideTsConfig();
179
175
  const pkgRename = 'package.json.bak';
180
176
 
181
177
  /**
@@ -194,7 +190,7 @@ const duel = async args => {
194
190
  // Build dual
195
191
  (0, _util.log)('Starting dual build...');
196
192
  try {
197
- await runBuild(dualConfigPath);
193
+ await runBuild(dualConfigPath, absoluteDualOutDir);
198
194
  } catch ({
199
195
  message
200
196
  }) {
@@ -211,7 +207,6 @@ const duel = async args => {
211
207
  });
212
208
  await (0, _promises.rename)((0, _nodePath.join)(pkgDir, pkgRename), pkg.path);
213
209
  if (success) {
214
- const absoluteDualOutDir = (0, _nodePath.join)(projectDir, dualOutDir);
215
210
  const filenames = await (0, _glob.glob)(`${absoluteDualOutDir}/**/*{.js,.d.ts}`, {
216
211
  ignore: 'node_modules/**'
217
212
  });
package/dist/duel.js CHANGED
@@ -48,19 +48,18 @@ const duel = async args => {
48
48
  const isCjsBuild = originalType !== 'commonjs';
49
49
  const targetExt = isCjsBuild ? '.cjs' : '.mjs';
50
50
  const hex = randomBytes(4).toString('hex');
51
- const getOverrideTsConfig = dualOutDir => {
51
+ const getOverrideTsConfig = () => {
52
52
  return {
53
53
  ...tsconfig,
54
54
  compilerOptions: {
55
55
  ...tsconfig.compilerOptions,
56
- outDir: dualOutDir,
57
56
  module: 'NodeNext',
58
57
  moduleResolution: 'NodeNext'
59
58
  }
60
59
  };
61
60
  };
62
61
  const runPrimaryBuild = () => {
63
- return runBuild(configPath, dirs ? isCjsBuild ? join(projectDir, outDir, 'esm') : join(projectDir, outDir, 'cjs') : undefined);
62
+ return runBuild(configPath, dirs ? isCjsBuild ? join(absoluteOutDir, 'esm') : join(absoluteOutDir, 'cjs') : absoluteOutDir);
64
63
  };
65
64
  const updateSpecifiersAndFileExtensions = async filenames => {
66
65
  for (const filename of filenames) {
@@ -86,10 +85,6 @@ const duel = async args => {
86
85
  const logSuccess = start => {
87
86
  log(`Successfully created a dual ${isCjsBuild ? 'CJS' : 'ESM'} build in ${Math.round(performance.now() - start)}ms.`);
88
87
  };
89
- await rm(absoluteOutDir, {
90
- force: true,
91
- recursive: true
92
- });
93
88
  if (parallel) {
94
89
  const paraName = `_${hex}_`;
95
90
  const paraParent = join(projectDir, '..');
@@ -122,8 +117,8 @@ const duel = async args => {
122
117
  filter: src => !/logs|pids|lib-cov|coverage|bower_components|build|dist|jspm_packages|web_modules|out|\.next|\.tsbuildinfo|\.npm|\.node_repl_history|\.tgz|\.yarn|\.pnp|\.nyc_output|\.grunt/i.test(src)
123
118
  });
124
119
  const dualConfigPath = join(paraTempDir, 'tsconfig.json');
125
- const dualOutDir = isCjsBuild ? join(outDir, 'cjs') : join(outDir, 'esm');
126
- const tsconfigDual = getOverrideTsConfig(dualOutDir);
120
+ const absoluteDualOutDir = join(paraTempDir, isCjsBuild ? join(outDir, 'cjs') : join(outDir, 'esm'));
121
+ const tsconfigDual = getOverrideTsConfig();
127
122
  await writeFile(dualConfigPath, JSON.stringify(tsconfigDual));
128
123
  await writeFile(join(paraTempDir, 'package.json'), JSON.stringify({
129
124
  type: isCjsBuild ? 'commonjs' : 'module'
@@ -133,7 +128,7 @@ const duel = async args => {
133
128
  let success = false;
134
129
  const startTime = performance.now();
135
130
  try {
136
- await Promise.all([runPrimaryBuild(), runBuild(dualConfigPath)]);
131
+ await Promise.all([runPrimaryBuild(), runBuild(dualConfigPath, absoluteDualOutDir)]);
137
132
  success = true;
138
133
  } catch ({
139
134
  message
@@ -141,13 +136,14 @@ const duel = async args => {
141
136
  logError(message);
142
137
  }
143
138
  if (success) {
144
- const absoluteDualOutDir = join(paraTempDir, dualOutDir);
145
139
  const filenames = await glob(`${absoluteDualOutDir}/**/*{.js,.d.ts}`, {
146
140
  ignore: 'node_modules/**'
147
141
  });
148
142
  await updateSpecifiersAndFileExtensions(filenames);
149
143
  // Copy over and cleanup
150
- await rename(absoluteDualOutDir, join(absoluteOutDir, isCjsBuild ? 'cjs' : 'esm'));
144
+ await cp(absoluteDualOutDir, join(absoluteOutDir, isCjsBuild ? 'cjs' : 'esm'), {
145
+ recursive: true
146
+ });
151
147
  await rm(paraTempDir, {
152
148
  force: true,
153
149
  recursive: true
@@ -168,8 +164,8 @@ const duel = async args => {
168
164
  }
169
165
  if (success) {
170
166
  const dualConfigPath = join(projectDir, `tsconfig.${hex}.json`);
171
- const dualOutDir = isCjsBuild ? join(outDir, 'cjs') : join(outDir, 'esm');
172
- const tsconfigDual = getOverrideTsConfig(dualOutDir);
167
+ const absoluteDualOutDir = join(projectDir, isCjsBuild ? join(outDir, 'cjs') : join(outDir, 'esm'));
168
+ const tsconfigDual = getOverrideTsConfig();
173
169
  const pkgRename = 'package.json.bak';
174
170
 
175
171
  /**
@@ -188,7 +184,7 @@ const duel = async args => {
188
184
  // Build dual
189
185
  log('Starting dual build...');
190
186
  try {
191
- await runBuild(dualConfigPath);
187
+ await runBuild(dualConfigPath, absoluteDualOutDir);
192
188
  } catch ({
193
189
  message
194
190
  }) {
@@ -205,7 +201,6 @@ const duel = async args => {
205
201
  });
206
202
  await rename(join(pkgDir, pkgRename), pkg.path);
207
203
  if (success) {
208
- const absoluteDualOutDir = join(projectDir, dualOutDir);
209
204
  const filenames = await glob(`${absoluteDualOutDir}/**/*{.js,.d.ts}`, {
210
205
  ignore: 'node_modules/**'
211
206
  });
package/dist/init.cjs CHANGED
@@ -109,7 +109,7 @@ const init = async args => {
109
109
  return false;
110
110
  }
111
111
  if (!tsconfig.compilerOptions?.outDir) {
112
- (0, _util.log)('No `outDir` defined in tsconfig.json. Build output will be in "dist".');
112
+ (0, _util.log)('No outDir defined in tsconfig.json. Build output will be in "dist".');
113
113
  }
114
114
  const projectDir = (0, _nodePath.dirname)(configPath);
115
115
  return {
package/dist/init.js CHANGED
@@ -103,7 +103,7 @@ const init = async args => {
103
103
  return false;
104
104
  }
105
105
  if (!tsconfig.compilerOptions?.outDir) {
106
- log('No `outDir` defined in tsconfig.json. Build output will be in "dist".');
106
+ log('No outDir defined in tsconfig.json. Build output will be in "dist".');
107
107
  }
108
108
  const projectDir = dirname(configPath);
109
109
  return {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@knighted/duel",
3
- "version": "1.0.0-rc.4",
3
+ "version": "1.0.0-rc.6",
4
4
  "description": "TypeScript dual packages.",
5
5
  "type": "module",
6
6
  "main": "dist",
@@ -52,11 +52,12 @@
52
52
  "c8": "^8.0.1",
53
53
  "eslint": "^8.45.0",
54
54
  "eslint-plugin-n": "^16.0.1",
55
- "prettier": "^3.0.0",
56
- "typescript": "^5.2.0-dev.20230727"
55
+ "prettier": "^3.0.1",
56
+ "typescript": "^5.2.0-dev.20230727",
57
+ "vite": "^4.4.8"
57
58
  },
58
59
  "dependencies": {
59
- "@knighted/specifier": "^1.0.0-rc.0",
60
+ "@knighted/specifier": "^1.0.0-rc.1",
60
61
  "glob": "^10.3.3",
61
62
  "read-pkg-up": "^10.0.0"
62
63
  },