{"id":15093186,"url":"https://github.com/angular/ts-minify","last_synced_at":"2025-10-06T11:31:38.304Z","repository":{"id":35006986,"uuid":"39101099","full_name":"angular/ts-minify","owner":"angular","description":"A tool to aid minification of Typescript code, using Typescript's type information.","archived":true,"fork":false,"pushed_at":"2019-02-26T22:06:39.000Z","size":193,"stargazers_count":122,"open_issues_count":16,"forks_count":7,"subscribers_count":25,"default_branch":"master","last_synced_at":"2025-10-06T00:33:44.720Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"OCA/connector-ecommerce","license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/angular.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-07-14T21:25:05.000Z","updated_at":"2025-10-04T01:09:43.000Z","dependencies_parsed_at":"2022-09-15T23:13:16.880Z","dependency_job_id":null,"html_url":"https://github.com/angular/ts-minify","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/angular/ts-minify","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/angular%2Fts-minify","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/angular%2Fts-minify/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/angular%2Fts-minify/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/angular%2Fts-minify/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/angular","download_url":"https://codeload.github.com/angular/ts-minify/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/angular%2Fts-minify/sbom","scorecard":{"id":196486,"data":{"date":"2025-08-11","repo":{"name":"github.com/angular/ts-minify","commit":"22f6fb8af0574bff7ce7e55da35bf3545c63b8fa"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":4.3,"checks":[{"name":"Code-Review","score":0,"reason":"Found 0/23 approved changesets -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Maintained","score":0,"reason":"project is archived","details":["Warn: Repository is archived."],"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Dangerous-Workflow","score":-1,"reason":"no workflows found","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Token-Permissions","score":-1,"reason":"No tokens found","details":null,"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"Pinned-Dependencies","score":-1,"reason":"no dependencies found","details":null,"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Vulnerabilities","score":10,"reason":"0 existing vulnerabilities detected","details":null,"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE:0","Info: FSF or OSI recognized license: Apache License 2.0: LICENSE:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Security-Policy","score":10,"reason":"security policy file detected","details":["Info: security policy file detected: github.com/angular/.github/SECURITY.md:1","Info: Found linked content: github.com/angular/.github/SECURITY.md:1","Info: Found disclosure, vulnerability, and/or timelines in security policy: github.com/angular/.github/SECURITY.md:1","Info: Found text in security policy: github.com/angular/.github/SECURITY.md:1"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"Branch-Protection","score":3,"reason":"branch protection is not maximal on development and all release branches","details":["Info: 'allow deletion' disabled on branch 'master'","Info: 'force pushes' disabled on branch 'master'","Warn: 'branch protection settings apply to administrators' is disabled on branch 'master'","Warn: branch 'master' does not require approvers","Warn: codeowners review is not required on branch 'master'","Warn: no status checks found to merge onto branch 'master'","Warn: PRs are not required to make changes on branch 'master'; or we don't have data to detect it.If you think it might be the latter, make sure to run Scorecard with a PAT or use Repo Rules (that are always public) instead of Branch Protection settings"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"SAST","score":0,"reason":"SAST tool is not run on all commits -- score normalized to 0","details":["Warn: 0 commits out of 1 are checked with a SAST tool"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}}]},"last_synced_at":"2025-08-16T21:54:59.998Z","repository_id":35006986,"created_at":"2025-08-16T21:54:59.998Z","updated_at":"2025-08-16T21:54:59.998Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":278602192,"owners_count":26014036,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-06T02:00:05.630Z","response_time":65,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-09-25T11:04:04.723Z","updated_at":"2025-10-06T11:31:37.905Z","avatar_url":"https://github.com/angular.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# TS-Minify (Experimental) [![Build Status](https://travis-ci.org/angular/ts-minify.svg)](https://travis-ci.org/angular/ts-minify)\n\n### About\n\n---\nTS-Minify is tool to aid in the reduction of code size for programs written in the [TypeScript](http://www.typescriptlang.org/) language. It is currently **highly experimental**.\n\nThis tool is developed on TypeScript and NodeJS, and transpiled to ES5; it uses the CommonJS module system.\n\n**There is currently no CLI or build-tool integration for TS-Minify.**\n\n### Table of Contents\n\n----------\n\n- [Motivation](#motivation)\n- [What it Does](#what-it-does)\n- [How Does it Work? The TL;DR](#how-does-it-work-the-tldr)\n- [External vs. Internal Types](#external-vs-internal-types)\n- [Structural Typing](#structural-typing)\n- [Usage](#usage)\n- [TSConfig Users](#tsconfig-users)\n- [Scope of Minification](#scope-of-minification)\n- [Caveats/Warnings](#caveatswarnings)\n- [Sample Measurements](#sample-measurements)\n- [Contributing](#contributing)\n- [Contributors](#contributors)\n- [License: Apache 2.0](#license-apache-20)\n- [Future](#future)\n\n### Motivation\n\n---\nAngular 2 (which is written in TypeScript) currently sits at around 135kb after being [Uglified](https://github.com/mishoo/UglifyJS) and compressed through GZIP. In comparison, Angular 1.4 is about 50kb, minified and compressed.\n\nA smaller bundle size means that less data needs to be transferred and loaded by the browser. This contributes to a better user experience.\n\nThe impetus for this tool was to reduce the code size of the Angular 2 bundle, but TS-Minify is meant to be a generic tool that can be used on programs written in TypeScript.\n\n\n### What it Does\n\n---\nTo achieve code size reduction, TS-Minify uses the idea of property renaming: take a TypeScript source file and rename properties to shorter property names, then re-emit the file as valid TypeScript.\n\n![TS-Minify role in minification pipeline](http://i.imgur.com/7iH4RyF.png) \u003csub\u003eThis diagram demonstrates TS-Minify's role in the intended minification pipeline.\u003c/sub\u003e\n\nTS-Minify *only*  targets property renaming. Minification tactics like whitespace removal, dead code removal, variable name mangling, etc. are taken care of by tools such as [UglifyJS](https://github.com/mishoo/UglifyJS). TS-Minify specifically targets property renaming since it is something that is difficult to achieve *safely* without type information. As such, TS-Minify requires a program to be correctly and throughly typed, otherwise, unwanted renaming may occur. \n\n### How Does it Work? The TL;DR\n\n---\nThe TypeScript Compiler API is utilized in order to access the Abstract Syntax Tree of a TypeScript source file. Identifiers that might be considered properties (such as identifiers in property declarations, property access expressions, method names in method declarations, etc.) are renamed to short names such as `a`, `b`, etc. after determining their renaming eligibility. A “renaming” global map is created with mappings from the original property name to the new generated property name so that re-namings are kept consistent between properties with the same names.\n\n```javascript\n{ maybeHandleCall: g }\n{ reportMissingType: h }\n{ getHandler: i }\n{ handlePropertyAccess: j }\n{ emitExtraImports: k }\n{ emit: l }\n{ visitTypeName: m }\n```\n\u003csub\u003eAn example of some mappings from the original property name to the shorter, generated property name.\u003c/sub\u003e\n\nThe renaming eligibility of a property takes several factors into consideration:\n\n- Does the property belong to an object declared in an external file ([`.d.ts file`](http://definitelytyped.org/))?\n- Does the property belong to a [standard built-in object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects)?\n- Does the property name belong to the DOM?\n\n### External vs. Internal Types\n\n---\nTS-Minify is able to safely rename properties by understanding which types are *external*, and which are not, to one's program.\n\nAn *external* type is something that you are bringing into your program. It is a type which you have not defined. This includes objects and functions from the JavaScript standard library, and JavaScript libraries like underscore.js or jQuery. If you are using external libraries, it is imperative that you include their corresponding `.d.ts` files.\n\nTypings for the standard library are included in the default library typings, `lib.d.ts`, which the TypeScript compiler uses during transpilation (it will typecheck your program at compile time) and does not need to be explicitly included.\n\n*Internal* types are ones that you, the programmer, have defined yourselves. Declaring a class `Foo` in your program tells the minifier that properties on `Foo` objects are within the renaming scope. Internal types also include things like object literal types.\n\n**Note**: If you want all internal sources to contain the same renamings, you should pass the relevant files together through a single pass of the minifier.\n\nAn example of what types are considered *external* and *internal*:\n\n```javascript\nvar x: { name: string, message: string }; // The object literal is an internal type\n\nvar x: Error; // Error is an external type\n\n// Structurally, the two are compatible, which brings us to the next section...\n```\n\n### Structural Typing\n\n---\nTypeScript uses a [structural type system](https://en.wikipedia.org/wiki/Structural_type_system). This means that objects and variables can be casted from one type to another as long as they are structurally compatible. Sometimes this means that external objects might be casted to internal objects, or vise versa.\n\nHere is an example of an external type being casted to an internal type:\n\n```javascript\nfunction x(foo: { name: string, message: string }) {\n\tfoo.name;\n\treturn foo; \n} \n\nx(new Error());\n```\n\nFunction `x` *expects* an internal object literal type. The call site `x(new Error())` passes an `Error` object as the parameter.\n\n[`Error`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error) is an object in the JavaScript standard library. Hence it is external to our small program above. Structurally, an `Error` object and the object literal `{ name: string, message: string }` are compatible. However, this means that we do not want to rename the properties on the object literal because we will likely want to access the properties of the `Error` object as we know them: `name` and `message`. If we renamed the properties of the object literal, it means that if an `Error` object is passed into a function call for `x()`, `foo.$some_renaming` will throw an error, because `Error` does not have property `$some_renaming`. \n\nHere is an example of an internal type being coerced into an external type:\n\n```javascript\nfunction ff(e: Error) { \n\treturn e.name; \n} \n\nff({ name: null, message: null });\n```\n\nThe parameter `e` on function `ff` is an external type to our program. We do not want to rename its properties. At the function call site, we are passing in an object literal type with properties `name` and `message`, which is structurally compatible with `Error`. We do not want to rename properties in the object literal because we need to coerce it into an external typing, which is expected to have properties `name` and `message`.\n\nAll of this is to say, the tool relies on type information to figure out if two types can be coerced into each other and whether their properties can be renamed based on the internal/external distinction. Type your programs! :)\n\n### Usage\n\n--- \n\nFirst clone the repo and run `npm install`.\n\n```shell\n$ git clone git@github.com:angular/ts-minify.git\n$ cd ts-minify\n$ npm install\n```\n\nCreate a new TypeScript file:\n\n```javascript\nimport {Minifier, options} from './src/main';\nvar minifier = new Minifier();\nminifier.renameProgram(['path/to/file.ts', 'path/to/another/file.ts', 'some/other/file.d.ts'], 'path/to/destination');\n```\n\nTranspile the above script into JavaScript using the TypeScript compiler and run it with Node:\n\n```shell\ntsc --module commonjs script.ts\nnode script.js\n```\n\nA new instance of the minifier takes an optional constructor argument:\n\n```javascript\nMinifierOptions {\n  failFast?: boolean;\n  basePath?: string;\n}\n```\n\n`failFast`: Setting `failFast` to true will throw an error when the minifier hits one.\n\n`basePath`:  Specifies the base path that the minifier uses to figure out to where to write the minfied TypeScript file. The `basePath` maybe be relative or absolute. All paths are resolved from the directory in which the minifier is executed. If there is no base path, the minified TypeScript file is outputted to the specified destination using a flattened file structure.\n\n`minifier.renameProgram()` takes a list of file names and an optional destination path:\n\n```javascript\nrenameProgram(fileNames: string[], destination?: string)\n```\n\n`renameProgram` accepts TypeScript files and `.d.ts` files. If you are not explicitly including typings using the reference path syntax in your TypeScript file, please pass in the `.d.ts` file so that the minifier can use the type information.\n\nThe minifier will uniformly rename the properties (which are available for renaming) across all the files that were passed in.\n\n### TSConfig Users\n\n---\nIf you are using a `tsconfig.json` file to reference your type definitions, pass in the `.d.ts` files for libraries used in your program to the minifier so that it can reference the type information for property renaming. The minfier does not have access to the `tsconfig.json` file. Otherwise, make sure to have `/// \u003creference path = 'foo.d.ts' /\u003e` at the top of your programs if you are using any external libraries.\n\n### Scope of Minification\n\n---\nCurrently, TS-Minify will do property renaming throughout all the files that are passed into it. The minifier excludes `.d.ts` files from renaming because those are the typing definitions of external libraries. If your TypeScript program exports objects across those files, the minifier will rename them uniformly in their declarations and their usage sites.\n\n### Caveats/Warnings\n\n---\nIn order to get the most out of the minifier, it is recommended that the user types their program as specifically and thoroughly as possible. In general, you should  avoid using the `any` type, and implicit `any`s in your code as this might result in unwanted naming.  \n\nWe recommend that you compile your TypeScript program with the  `noImplicitAny` compiler flag enabled before trying the minifier.\n\nPlease avoid explicit any casting: \n\n```javascript\n// example of explicit any casting\nvar x = 7; \n\u003cany\u003ex;\n```\n\n### Sample Measurements\n\n---\nTS-Minify was run on a well-typed TypeScript program with the following stats and results:\n\n- Approximately 2100 lines of code (split across 10 files)\n- Unminified and Uglified: 72kb\n- Minified and Uglified: 56kb (codesize reduction of about 20%)\n- About 6% - 8% codesize reduction after minification, Uglification, and GZIP compression.\n\n### Contributing\n\n---\nClone the repository from GitHub:\n\n```shell\n$ git clone git@github.com:angular/ts-minify.git\n$ cd ts-minify\n$ npm install\n```\n\nRun the unit tests with `gulp unit.test`\n\nRun the end-to-end tests with `gulp e2e.test`.\n\nThis project uses `clang-format`. Run `gulp test.check-format` to make sure code you write conforms to this standard.\n\n- If you need some guidance on understanding TypeScript, look at the [TypeScript GitHub Wiki](https://github.com/Microsoft/TypeScript/wiki).\n- If you need a quick introduction to the TS Compiler API, take a look at the page on using the [TS Compiler](https://github.com/Microsoft/TypeScript/wiki/Using-the-Compiler-API) API. \n- Take a look at the `typescript.d.ts` for type signatures, and to understand what is available to you from the TS toolchain.\n\nIf you need some help debugging, there is a  `DEBUG` flag that can be enabled in `src/main.ts`:\n\n```javascript\nconst DEBUG = true; // switch from false to true to enable the console.logs\n```\n\nThere are some helpful print statements which print out: \n\n- the `SyntaxKind` of the nodes being traversed\n- the minified string output\n- a dictionary of external/internal type casts\n\nRemember to switch the `DEBUG` flag off afterwards.\n\n### Contributors\n\n---\nDaria Jung (Google intern)\n\n\n### License: Apache 2.0\n\n---\n```\nCopyright 2015 Google, Inc. http://angular.io\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\n    http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n```\n### Future\n\n---\n\nProperty renaming is hard and there are a lot of [issues](https://github.com/angular/ts-minify/issues)! If you're interesting in contributing to this project, please check some of them out.\n\nIssues are labelled `easy`, `medium`, and `hard`. Some have a `Needs Exploration` label which means you might have to poke around a bit before reaching conclusions about how to tackle the problem!\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fangular%2Fts-minify","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fangular%2Fts-minify","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fangular%2Fts-minify/lists"}