@joycostudio/chopper 0.2.0 → 0.3.0

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/dist/cli/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
2
  import { readFile, readdir, mkdir, copyFile, mkdtemp, writeFile, rename, rm } from 'fs/promises';
3
- import { extname, parse, join, dirname, resolve, relative, basename } from 'path';
3
+ import { extname, parse, join, dirname, resolve, relative, isAbsolute, sep, basename } from 'path';
4
4
  import { PropertyType, NodeIO } from '@gltf-transform/core';
5
5
  import { ALL_EXTENSIONS, EXTTextureWebP, EXTTextureAVIF, KHRTextureBasisu } from '@gltf-transform/extensions';
6
6
  import draco3d from 'draco3dgltf';
@@ -103,7 +103,7 @@ function outputMimeType(encoding) {
103
103
 
104
104
  // package.json
105
105
  var package_default = {
106
- version: "0.2.0"};
106
+ version: "0.3.0"};
107
107
 
108
108
  // src/codecs/manifest.ts
109
109
  var CODEC_MANIFEST_HASH = "2046d60deb0f9f224743f4404f3c6e8ba5399f81b2811fa50466e93fce3bd322";
@@ -1148,7 +1148,7 @@ async function runConfig(options = {}) {
1148
1148
  const mode = options.mode ?? "write";
1149
1149
  const loaded = options.config ? success(options.config) : await loadConfig(resolve(cwd, options.configPath ?? "chopper.config.ts"));
1150
1150
  if (!loaded.ok) return loaded;
1151
- const planned = await planAssets(loaded.data, cwd);
1151
+ const planned = await planAssets(loaded.data, cwd, options.outputDirectory);
1152
1152
  if (!planned.ok) return planned;
1153
1153
  const chopper2 = options.chopper ?? createNodeChopper();
1154
1154
  const files = await mapConcurrent(
@@ -1158,8 +1158,9 @@ async function runConfig(options = {}) {
1158
1158
  );
1159
1159
  return success({ mode, files, totals: summarize(files) });
1160
1160
  }
1161
- async function planAssets(config, cwd) {
1161
+ async function planAssets(config, cwd, outputDirectory) {
1162
1162
  const planned = [];
1163
+ const outputRoot = outputDirectory ? resolve(cwd, outputDirectory) : void 0;
1163
1164
  for (const rule of config.rules) {
1164
1165
  const valid = validateRecipe(rule.recipe);
1165
1166
  if (!valid.ok) return valid;
@@ -1169,9 +1170,14 @@ async function planAssets(config, cwd) {
1169
1170
  onlyFiles: true
1170
1171
  });
1171
1172
  for (const match of matches.sort()) {
1173
+ const configuredOutput = resolveOutput(rule, match, cwd);
1174
+ const relativeOutput = relative(cwd, configuredOutput);
1175
+ if (outputRoot && (isAbsolute(relativeOutput) || relativeOutput === ".." || relativeOutput.startsWith(`..${sep}`))) {
1176
+ return failure("invalid_recipe", `Cannot stage output outside the project: ${configuredOutput}`);
1177
+ }
1172
1178
  planned.push({
1173
1179
  input: resolve(cwd, match),
1174
- output: resolveOutput(rule, match, cwd),
1180
+ output: outputRoot ? resolve(outputRoot, relativeOutput) : configuredOutput,
1175
1181
  rule
1176
1182
  });
1177
1183
  }