UNPKG

@nx/remix

Version:

The Remix plugin for Nx contains executors and generators for managing Remix applications and libraries within an Nx workspace. It provides: - Integration with libraries such as Vitest, Jest, Playwright, Cypress, and Storybook. - Generators for applica

28 lines (27 loc) 1.05 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.insertStatementAfterImports = insertStatementAfterImports; const devkit_1 = require("@nx/devkit"); const typescript_1 = require("typescript"); /** * Insert a statement after the last import statement in a file */ function insertStatementAfterImports(tree, path, statement) { const contents = tree.read(path, 'utf-8'); const sourceFile = (0, typescript_1.createSourceFile)(path, contents, typescript_1.ScriptTarget.ESNext); const importStatements = sourceFile.statements.filter(typescript_1.isImportDeclaration); const index = importStatements.length > 0 ? importStatements[importStatements.length - 1].getEnd() : 0; if (importStatements.length > 0) { statement = `\n${statement}`; } const newContents = (0, devkit_1.applyChangesToString)(contents, [ { type: devkit_1.ChangeType.Insert, index, text: statement, }, ]); tree.write(path, newContents); }