brillout / goldpage

Page Builder.
Creative Commons Zero v1.0 Universal
57 stars 3 forks source link

stripSameSuffixAndPrefix(arr) in @goldpage/webpack/runBuild.js fails when arr has length one #7

Closed chriscalo closed 4 years ago

chriscalo commented 4 years ago

I made some progress integrating Goldpage into my app, but when running goldpage dev, I was getting an error.

I kept the setup minimal. Here's pages/index.page.js:

import test from "./test.vue";

export default {
  route: "/",
  view: test,
  renderToHtml: true,
};

And here's pages/test.vue:

<template>
  <div>
    test
  </div>
</template>

I followed the stack trace to @goldpage/webpack/runBuild.js and inserted a console.log() statement to see what was happening:

    stripSameSuffixAndPrefix(
      configFilePaths
      .filter(isNotDraft)
    )
    .forEach(({original, stripped}) => {
      const pageName = stripped;
      const pageConfigFile = original;
      // INSERTED FOR DEBUGGING
      console.log({
        pageName,
        pageConfigFile,
        pageFiles,
      });
      // END INSERTED FOR DEBUGGING
      assert.internal(pageName);
      assert.internal(pageConfigFile);
      pageFiles[pageName] = pageConfigFile;
    });

It seems to be throwing in this line:

      assert.internal(pageName);

Here's the error output:

Building pages...
{ pageName: '',
  pageConfigFile: '/Users/chriscalo/Projects/viaticus/pages/index.page.js',
  pageFiles: {} }
****************************************
************* Stack Trace **************
****************************************
Error:
    at stripSameSuffixAndPrefix.forEach (/Users/chriscalo/Projects/viaticus/node_modules/@goldpage/webpack/runBuild.js:136:14)
    at Array.forEach (<anonymous>)
    at Function.getPageFiles (/Users/chriscalo/Projects/viaticus/node_modules/@goldpage/webpack/runBuild.js:128:6)
    at Function.<anonymous> (/Users/chriscalo/Projects/viaticus/node_modules/webpack-ssr/Build.js:111:46)
    at Generator.next (<anonymous>)
    at buildAll (/Users/chriscalo/Projects/viaticus/node_modules/@rebuild/iso/IsoBuilder.js:327:36)

****************************************
************ Internal Error ************
****************************************

I was able to track things down to stripSameSuffixAndPrefix(arr) assumes that arr has at least 2 entries because it seems to compare them to each other.

Should it instead strip away the pages directory path and the .page.js extension, something like the following?

configFilePaths
  .filter(isNotDraft)
  .map(filePath => { original: filePath, stripped: pageName(filePath) })
    .forEach(({original, stripped}) => {
    const pageName = stripped;
    const pageConfigFile = original;
    assert.internal(pageName);
    assert.internal(pageConfigFile);
    pageFiles[pageName] = pageConfigFile;
  });

function pageName(fullPath) {
  const pathToPagesDir = path.resolve("path/to/pages");
  const name = fullPath
    .replace(pathToPagesDir, "")
    .replace(".page.js", "");
  return name;
};

For now, I found a workaround of ensuring that I have at least two *.page.js files in the pages directory.

brillout commented 4 years ago

Fixed & new Goldpage version 0.5.4 published.

chriscalo commented 4 years ago

Working perfectly now, thanks 👍