Skip to content

Use classes do not allow for paths outside of current folder #114

@struct78

Description

@struct78

A couple of things:

I think the update from 3.2.7 to 3.2.8 should have had a major version bump.

We have our project structure set up in a way that mimics the use of Java classes. For example, we have a simple file loader that outputs SVG code inline so it can be styled.

<sly data-sly-use.svg="${'com.companyname.project.InlineSvgUtility' @ svgPath=properties.logo}">
    ${logo.svgItem @ context='unsafe'}
</sly>

We then used the withUseDirectory method of the runtime to load modules from the 'modules/' folder in the root e.g.

const fse = require('fs-extra')
const path = require('path')

class InlineSvgUtility {
  async use() {
    const assetsPath = 'assets/icons/'

    if (!this.svgPath) {
      return {
        svgItem: null,
      }
    }

    const data = await fse.readFile(path.join(assetsPath, this.svgPath), 'utf-8')

    return {
      svgItem: data,
    }
  }
}

module.exports = InlineSvgUtility

So this sits in src/modules/com.companyname.project.InlineSvgUtility.js, and was working happily. In 3.2.8 the withUseDirectory seems to effectively do nothing.

This line seems to be the cause.

6d00698#diff-59e501da46af5081071db46e7c50a748R243

If the path doesn't start with './' (e.g. '../'), it will attempt to resolve files relative to the folder the Compiler script is in, rather than the baseDir. For example, this will throw a "MODULE_NOT_FOUND" error.

<sly data-sly-use.svg="${'../modules/com.companyname.project.InlineSvgUtility' @ svgPath=properties.logo}">
    ${logo.svgItem @ context='unsafe'}
</sly>

I can fix it by traversing up 6 or so folders out of the node_modules, but that's not ideal.

<sly data-sly-use.svg="${'../../../../../../modules/com.companyname.project.InlineSvgUtility' @ svgPath=properties.logo}">
    ${logo.svgItem @ context='unsafe'}
</sly>

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions