Skip to content

Wrong reference in source map for files in subfolders #666

Open
@haoadoreorange

Description

@haoadoreorange

Expected behavior:
Go up mutiple level in sources path of .map file depending on the location in subfolder

Actual behavior:
Same level for all

Your gulpfile:

Include your gulpfile, or only the related task (with ts.createProject).

const sourcemaps = require(`gulp-sourcemaps`);
const tsProject = require(`gulp-typescript`).createProject(`tsconfig.build.json`);
const gulp = require(`gulp`);
exports.default = () => {
    const compiled_src = tsProject
        .src()
        .pipe(sourcemaps.init())
        .pipe(
            require(`gulp-strip-code`)({
                start_comment: `<DEV-ONLY>`,
                end_comment: `</DEV-ONLY>`,
            }),
        )
        .pipe(tsProject());
    return require(`merge-stream`)(
        compiled_src.js
            .pipe(require(`gulp-uglify`)({ keep_fnames: true }))
            .pipe(sourcemaps.write(`.`, { includeContent: false }))
            .pipe(gulp.dest(`dist`)),
        compiled_src.dts.pipe(sourcemaps.write(`.`, { includeContent: false })).pipe(gulp.dest(`dist`)),
    );
};

tsconfig.json

Include your tsconfig, if related to this issue.

// tsconfig.build.json
{
    "extends": "./tsconfig.json",
    "compilerOptions": {
        "rootDir": "src/",
        "declaration": true
    },
    "exclude": ["test/", "dist/"]
}

// tsconfig.json
{
    "extends": "@tsconfig/node14/tsconfig.json",
    "compilerOptions": {
        "outDir": "dist/" /* Redirect output structure to the directory. */,
        "lib": ["ES2020", "ES2021.String"],
        "baseUrl": "src/" /* Base directory to resolve non-absolute module names. */,
        "plugins": [{ "transform": "@zerollup/ts-transform-paths" }]
    }
}

// @tsconfig/node14/tsconfig.json
{
  "$schema": "https://json.schemastore.org/tsconfig",
  "display": "Node 14",

  "compilerOptions": {
    "lib": ["es2020"],
    "module": "commonjs",
    "target": "es2020",

    "strict": true,
    "esModuleInterop": true,
    "skipLibCheck": true,
    "forceConsistentCasingInFileNames": true
  }
}

Code

Include your TypeScript code, if necessary.

// src/index.ts
export {}

// dist/index.js.map
{"version":3,"sources":["../src/index.ts"], ... // correct

// src/lib/polyfill.ts
export {}

// dist/lib/polyfill.js.map
{"version":3,"sources":["../src/lib/polyfill.ts"], ... // wrong, should be ../../src/lib....

This might be related to #644, although I'm not sure

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions